#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
char s[500500];
int n, last, a[500500];
int calc(int cur) {
  int ed = n;
  for (int i = 0; i < n; i++) {
    if (i > last && cur >= 0) {
      ed = i;
      break;
    }
    a[i] = 1;
    if (cur < 0) a[i]++;
    cur += (s[i] == 'S' ? 1 : (s[i] == 'H' ? -1 : 0));
    if (cur < 0) a[i]++;
  }
  if (cur < 0) return 0x3f3f3f3f;
  int ans = 2 * ed - 1, sum = 0;
  for (int i = 0; i < ed; i++) {
    sum += a[i];
    if (a[i] == 1) smin(ans, sum + max(0, 2 * (ed - i - 1) - 1));
  }
  return ans;
}
int main() {
  int t;
  cin >> n >> t;
  scanf("%s", s);
  for (int i = 0; i < n; i++)
    if (s[i] == 'H') last = i;
  int st = -1, ed = n + 1, mid;
  while (ed - st > 1) {
    mid = st + ed >> 1;
    if (calc(mid) <= t)
      ed = mid;
    else
      st = mid;
  }
  printf("%d\n", ed <= n ? ed : -1);
  return 0;
}
