#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
int n, t, h, s;
char road[500001];
int H[500001], S[500001];
bool time(int k) {
  vector<pair<int, int> > step;
  step.push_back(make_pair(-1, -1));
  for (int i = 0, j = 0; i < h; i++) {
    if (k) {
      k--;
      step.push_back(make_pair(H[i], H[i]));
    } else if (H[i] > S[j]) {
      step.push_back(make_pair(H[i], H[i]));
      j++;
    } else {
      int l = (int)(step.size()) - 1;
      if (H[i] < step[l].second)
        step[l].second = S[j];
      else
        step.push_back(make_pair(H[i], S[j]));
      j++;
    }
  }
  int tt = 0;
  for (int i = 1; i < (int)(step.size()); i++) {
    tt +=
        (step[i].second - step[i - 1].first) + (step[i].second - step[i].first);
  }
  tt = min(tt, (n * 2) - 1);
  return tt <= t;
}
int main() {
  scanf("%d %d\n", &n, &t);
  scanf("%s\n", road);
  h = 0, s = 0;
  for (int i = 0; i < n; i++) {
    if (road[i] == 'H') H[h++] = i;
    if (road[i] == 'S') S[s++] = i;
  }
  if (H[h - 1] >= t) {
    cout << -1 << endl;
    return 0;
  }
  int r = max(h - s, 0), e = h;
  while (r < e) {
    int mi = (r + e) >> 1;
    (time(mi)) ? e = mi : r = mi + 1;
  }
  cout << e << endl;
  return 0;
}
