#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
int countH, countS;
int maxH;
int v[MAXN];
int i;
int n, t;
string s;
int l, r, m;
bool trial(int candy) {
  int maxS;
  int start, used;
  for (i = maxH; i < n; i++) {
    if (v[i] == -candy) {
      maxS = i;
      break;
    } else {
      maxS = maxH;
    }
  }
  start = -1;
  used = 0;
  for (i = 0; i < n; i++) {
    used++;
    if (start == -1 && (v[i] + candy == -1)) {
      if (used + 2 * (maxS - i) <= t) {
        return true;
      }
      start = i;
    }
    if (start != -1 && (v[i] + candy == 0)) {
      used += 2 * (i - start);
      start = -1;
    }
    if (used > t) {
      return false;
    }
    if (i >= maxH && start == -1) {
      return true;
    }
  }
  return true;
}
int main() {
  cin >> n >> t;
  cin >> s;
  countH = 0;
  countS = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'H') {
      countH++;
      v[i] = v[i - 1] - 1;
      maxH = i;
    } else if (s[i] == 'S') {
      countS++;
      v[i] = v[i - 1] + 1;
    } else {
      v[i] = v[i - 1];
    }
  }
  if (t < maxH + 1) {
    cout << -1 << endl;
    exit(0);
  }
  l = max(countH - countS, 0);
  r = countH;
  while (l != r) {
    m = (l + r) / 2;
    if (trial(m)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << r << endl;
}
