#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

#define let auto
#define fn auto
typedef size_t usize;
using namespace std;

fn fastio() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

fn main() -> int {
    usize n, k;
    cin >> n >> k;
    let line = vector<char>(n);
    let valid = vector<bool>(n, false);
    for (usize i = 0; i < n; i++) {
        char t;
        cin >> t;

        line[i] = t;
        if (t == 'H') {
            valid[i] = true;
        }
    }

    // left assoc

    let count = 0;
    for (usize i = 0; i < n; i++) {
        if (line[i] == 'P') {
            let left = i >= k ? i - k : 0;
            let right = i + k >= n ? n - 1 : i + k;

            for (usize j = left; j <= right; j++) {
                if (valid[j]) {
                    count += 1;
                    valid[j] = false;
                    break;
                }
            }
        }
    }

    cout << count << endl;
}