#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
char s[500105];
int t, sh;
int ss[500105], dp[500105], Q[500105];
int cal(int val) {
  int sum = 1 << 30, ans = 1, l = -1, c = 0, len = 0;
  for (int i = 0; i < n; i++, ans++) {
    if (s[i] == 'S') {
      val++;
      if (val == 0 && l != -1) {
        ans += 2 * (i - l);
      }
    } else if (s[i] == 'H') {
      val--;
      c++;
      if (val == -1) {
        l = i;
        dp[i] = ans;
        Q[len++] = i;
      }
    }
    if (c == sh && val >= 0) {
      sum = ans;
      for (int(j) = 0; (j) < (int)(len); (j)++) {
        int u = Q[j];
        sum = min(sum, dp[u] + (i - u) * 2);
      }
      break;
    }
  }
  return sum;
}
int main() {
  scanf("%d%d", &n, &t);
  scanf("%s", s);
  int lastH = 0;
  for (int i = 0; s[i]; i++) {
    ss[i] = ss[i - 1];
    if (s[i] == 'H') {
      sh++;
      lastH = i;
    } else if (s[i] == 'S')
      ss[i]++;
  }
  int l = 0, r = n + 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (cal(mid) <= t)
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r == n + 1 ? -1 : r);
  return 0;
}
