#include <bits/stdc++.h>
using namespace std;
int n, t, La;
char s[10000000];
bool ok(int x, int maxn) {
  int cnt = x, cur = 0, tmp = 10000000, pos, last = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'H')
      cnt--;
    else if (s[i] == 'S')
      cnt++;
    if (cnt == 0 && last == -1) maxn = max(maxn, i);
    last = cnt;
  }
  cnt = x, last = 0;
  for (int i = 1; i <= maxn; i++) {
    cur++;
    if (s[i] == 'H')
      cnt--;
    else if (s[i] == 'S')
      cnt++;
    if (last == 0 && cnt == -1) {
      tmp = min(tmp, cur + 2 * (maxn - i));
      pos = i;
    }
    if (last == -1 && cnt == 0) {
      cur += 2 * (i - pos);
    }
    last = cnt;
  }
  return min(tmp, cur) <= t;
}
int main() {
  cin >> n >> t >> s + 1;
  int ch = 0, cs = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'H') {
      La = i;
      ch++;
    } else if (s[i] == 'S')
      cs++;
  }
  int l = max(0, ch - cs) - 1;
  int r = 10000000;
  if (La > t) {
    cout << "-1" << endl;
  } else {
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (ok(mid, La))
        r = mid;
      else
        l = mid;
    }
    cout << r << endl;
  }
}
