#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5;
int n, t, s, h, type[N];
void update(int& val, int v) {
  if (val == -1 || val > v) val = v;
}
bool test(int cnt) {
  int cur = cnt;
  int have = s + cur;
  int last = n - 1;
  while (type[last] == 0 || type[last] == 2 && have > h) {
    if (type[last] == 2) have--;
    last--;
  }
  int ans = -1;
  int cur_res = 1;
  queue<int> q;
  for (int i = 0; i <= last; i++) {
    if (type[i] == 1) q.push(i);
    if (type[i] == 2) cur++;
    if (q.size()) update(ans, cur_res + last - i + last - q.front());
    if (q.size() && cur >= q.size()) {
      cur_res += 2 * (i - q.front());
      while (q.size()) {
        q.pop(), cur--;
      }
    }
    cur_res += 1;
  }
  update(ans, cur_res);
  return ans <= t;
}
int main() {
  cin >> n >> t;
  int last_h = -1;
  for (int i = 0; i < n; i++) {
    char t;
    cin >> t;
    if (t == '.')
      type[i] = 0;
    else if (t == 'H') {
      type[i] = 1;
      h++;
      last_h = i;
    } else {
      type[i] = 2;
      s++;
    }
  }
  if (last_h + 1 > t) {
    cout << -1 << endl;
    return 0;
  }
  int l = max(-1, h - s - 1), r = h;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (test(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
  return 0;
}
