#include <bits/stdc++.h>
using namespace std;
template <class T>
bool checkMin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool checkMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const int MN = 5 * 1e5 + 5;
int n, t, H;
char in[MN];
bool ok(int noSweet) {
  int anzHinter = 0, hinterstes = 0, mt = 0, houses = 0;
  for (int i = 0; i < (n); i++) {
    if (in[i] == 'H') {
      if (noSweet > 0 && anzHinter == 0)
        noSweet--, houses++;
      else {
        if (anzHinter++ == 0) hinterstes = i;
      }
    } else if (in[i] == 'S') {
      noSweet++;
      if (noSweet >= anzHinter && anzHinter) {
        int d = (i - hinterstes);
        houses += anzHinter;
        mt += 2 * d;
        mt -= (houses == H) * d;
        noSweet -= anzHinter;
        anzHinter = 0;
      }
    }
    mt++;
    if (houses == H) break;
  }
  return mt <= t && houses == H;
}
int binsearch() {
  if (n * 2 - 1 <= t && count(in, in + n, 'S') >= H) return 0;
  int lo = 0, hi = n;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (ok(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  if (!ok(lo)) return -1;
  return lo;
}
int main() {
  scanf("%d %d\n", &n, &t);
  scanf("%s\n", in);
  H = count(in, in + n, 'H');
  printf("%d\n", binsearch());
}
