#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int aabs(int a) {
  if (a < 0) return -a;
  return a;
}
string s;
int n, t;
int nh, ns;
int d[500013];
bool bb[500013];
bool f(int m) {
  if (ns + m < nh) {
    return false;
  }
  int ck = m, ch = 0;
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      ch++;
    }
    if (s[i] == 'S') {
      ck++;
    }
    if (ck < ch) {
      cnt += 3;
      d[i] = cnt;
      bb[i] = false;
    } else {
      bb[i] = true;
      cnt++;
      d[i] = cnt;
      if (ch == nh) {
        int mn = 2 * i + 1;
        for (int j = 0; j < i; j++) {
          if (bb[j]) {
            mn = min(mn, d[j] + 2 * (i - j - 1));
          }
        }
        return t >= mn;
      }
    }
  }
}
int main() {
  nh = 0;
  ns = 0;
  cin >> n >> t >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      nh++;
    } else {
      if (s[i] == 'S') {
        ns++;
      }
    }
  }
  int l = 0, r = s.size();
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (f(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  if (f(l)) {
    r = l;
  }
  if (!f(r)) {
    cout << -1;
  } else {
    cout << r;
  }
  return 0;
}
