#include <bits/stdc++.h>
using namespace std;
int n, t, h;
string str;
bool check(int b) {
  int tr[500010], i = 0, now = 0;
  for (int cnt = 0; (cnt < h || b < 0) && i < n; i++) {
    tr[i] = 1;
    if (b < 0) tr[i]++;
    if (str[i] == 'H')
      b--, cnt++;
    else if (str[i] == 'S')
      b++;
    if (b < 0) tr[i]++;
    now += tr[i];
  }
  int best = now;
  now += (1 - tr[--i]);
  for (--i; i >= 0; --i) {
    best = min(best, (now += 2 - tr[i]));
  }
  if (b < 0 || best > t)
    return false;
  else
    return true;
}
int bins(int l, int r) {
  if (l > r) return l;
  int mid = (l + r) / 2;
  if (check(mid))
    bins(l, mid - 1);
  else
    bins(mid + 1, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> t >> str;
  for (int i = 0; i < n; i++)
    if (str[i] == 'H') h++;
  if (str.find_last_of('H') >= t)
    cout << -1 << endl;
  else
    cout << bins(0, 500010) << endl;
  return 0;
}
