#include <bits/stdc++.h>
using namespace std;
int n, t;
char s[1 << 20];
int mark[1 << 20];
int calc(int k) {
  int now = 1, x = 1, y = -1, last = -1;
  for (int i = (1); i <= (n); i++) mark[i] = 0;
  for (int i = (1); i <= (n); i++) {
    if (now == i && s[i] == 'S') k++, now++;
    if (s[i] != 'H') continue;
    last = max(last, i);
    if (y < i) {
      if (y != -1) mark[x] = y;
      x = i;
      y = -1;
    }
    if (k) {
      k--;
      continue;
    }
    while (now <= n && s[now] != 'S') now++;
    if (now <= n) {
      if (now > i) {
        y = now;
        last = now;
      }
      now++;
    } else
      return 1 << 30;
  }
  if (y != -1) mark[x] = y;
  int ans = 1 << 30, sum = 0;
  for (int i = (1); i <= (n); i++)
    if (mark[i]) {
      ans = min(ans, sum + i - 1 + (last - i) * 2);
      sum += 2 * (mark[i] - i);
    }
  ans = min(ans, sum + last - 1);
  return ans;
}
int main() {
  cin >> n >> t;
  scanf("%s", s + 1);
  t--;
  int l = 0, r = n, ans = -1;
  while (l <= r) {
    int mid = (r - l) / 2 + l, tmp = calc(mid);
    if (tmp <= t)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
