#include <bits/stdc++.h>
const int N = 500010;
using namespace std;
int n, t, p[N];
char s[N];
long long dp[N];
long long work(int x) {
  int k = 0, cnt = 0, id = 0;
  for (int i = 1; i <= n; i++)
    if (s[i] == 'H') id = k = i, cnt++;
  long long tmp = x;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'S') tmp++;
    if (tmp == cnt && s[i] != '.') k = max(k, i);
  }
  if (tmp < cnt) return 1e18;
  p[0] = x;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'H')
      p[i] = p[i - 1] - 1;
    else if (s[i] == 'S')
      p[i] = p[i - 1] + 1;
    else
      p[i] = p[i - 1];
  }
  long long ret = 1e18;
  tmp = 0;
  for (int i = 1, j = 0; i <= id; i++) {
    tmp++;
    if (p[i] == -1 && s[i] == 'H') {
      j = i;
      while (p[j] != 0) j++;
      ret = min(ret, tmp + (k - i) * 2);
      tmp += 3 * (j - i);
      i = j;
      continue;
    }
  }
  ret = min(ret, tmp);
  return ret;
}
int main() {
  scanf("%d%d%s", &n, &t, s + 1);
  int l = 0, r = n, ret = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (work(mid) <= t)
      r = mid - 1, ret = mid;
    else
      l = mid + 1;
  }
  cout << ret << endl;
  return 0;
}
