#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
  istringstream sin(s);
  int t;
  sin >> t;
  return t;
}
template <class T>
string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
void chmin(T &t, T f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
  if (t < f) t = f;
}
char s[500010];
int n, t;
int nh = 0, ns = 0;
int p;
bool ok(int k) {
  int i;
  int cnt = k;
  int pre = 0;
  int T = 0;
  vector<int> pos, len;
  for (i = (0); i < (n); i++) {
    T++;
    if (s[i] == 'H') {
      if (cnt == 0) {
        pre = i;
        pos.push_back(i);
      }
      cnt--;
    } else if (s[i] == 'S') {
      cnt++;
      if (cnt == 0) {
        T += (i - pre) * 2;
        len.push_back(i - pre);
      }
    }
    if (i >= p && cnt >= 0) break;
  }
  pos.push_back(i);
  for (int j = pos.size() - 1; j > 0; j--) {
    if (pos[j] - pos[j - 1] <= len[j - 1] * 2)
      T = T - len[j - 1] * 2 + pos[j] - pos[j - 1];
    else
      break;
  }
  return T <= t;
}
int main() {
  cin >> n >> t;
  scanf("%s", s);
  int i;
  for (i = (0); i < (n); i++) {
    if (s[i] == 'H') {
      nh++;
      chmax(p, i);
    } else if (s[i] == 'S')
      ns++;
  }
  int lo = 0, hi = nh;
  if (nh > ns) lo = nh - ns;
  while (lo <= hi) {
    int m = (lo + hi) / 2;
    if (ok(m))
      hi = m - 1;
    else
      lo = m + 1;
  }
  if (lo > nh)
    puts("-1");
  else
    cout << lo << endl;
  return 0;
}
