#include <bits/stdc++.h>
using namespace std;
int n, t, maxx;
string s;
bool calc(int k) {
  int c = k;
  long long tt = 0, o = 0, l = -1, ll = -1, ma = 4 * 1e9, ttt;
  bool ok = 0, ook = 0;
  for (int i = 0; i < n; i++) {
    if (c >= o && ll != -1 && i >= maxx) ma = i - ll + 1 + ttt, ll = -1;
    if (s[i] == 'H' && c) {
      c--;
    } else if (s[i] == 'S') {
      c++;
      if (c >= o && l != -1 && i > maxx) tt -= (i - l);
      if (c >= o && l != -1) tt += 2 * (i - l), c -= o, o = 0, l = -1, ok = 0;
    } else if (s[i] == 'H' && !c && !ok) {
      l = i;
      if (!ook) ll = i, ook = 1, ttt = tt;
      o++;
      ok = 1;
    } else if (s[i] == 'H' && c < o && ok) {
      o++;
    }
    tt++;
    if (!o && i >= maxx) {
      if (i == maxx && c)
        break;
      else if (i != n - 1)
        tt--;
      else
        break;
    }
  }
  if (min(tt, ma * 2 - 1) <= t && !o) return 1;
  return 0;
}
int main() {
  cin >> n >> t;
  cin >> s;
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == 'H') maxx = max(i - 1, maxx);
  int l = -1, r = 5 * 100000 + 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (calc(m))
      r = m;
    else
      l = m;
  }
  if (r == 500001)
    cout << -1;
  else
    cout << r;
  return 0;
}
