#include <bits/stdc++.h>
using namespace std;
const long long maxn = 500000 + 66;
const long long mod = 1e9 + 7;
long long n, k;
char ch[maxn];
bool check(long long x) {
  long long num = x;
  long long ends = 0;
  for (long long i = 0; i < n; i++) {
    if (ch[i] == 'H') {
      num--;
      ends = i;
    } else if (ch[i] == 'S') {
      num++;
      if (num == 0) ends = i;
    }
  }
  if (num < 0) return 0;
  long long ans = 0;
  long long last = -1;
  num = x;
  for (long long i = 0; i <= ends; i++) {
    ans++;
    if (ch[i] == 'H') {
      num--;
      if (num == -1) {
        long long backs = (ends - i) * 2;
        if (backs + ans <= k) return 1;
        last = i;
      }
    } else if (ch[i] == 'S') {
      num++;
      if (num == 0) {
        long long backs = (i - last) * 2;
        ans += backs;
      }
    }
  }
  return ans <= k;
}
int main() {
  scanf("%lld %lld", &n, &k);
  cin >> ch;
  long long l = 0, r = n;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%lld\n", check(l) ? l : -1);
}
