#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int n, m;
char s[500005];
int gao(int cnt) {
  int ret = 0, x = 0;
  vector<pair<int, int> > u;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S')
      if (++cnt == 0) u.push_back({x, i});
    if (s[i] == 'H')
      if (cnt-- == 0) x = i;
  }
  int t = n - 1;
  while (s[t] != 'H' && (u.empty() || t > u.back().second)) t--;
  int sum = t + 1;
  for (auto r : u) sum += (r.second - r.first) * 2;
  ret = sum;
  for (size_t i = u.size() - 1; ~i; i--) {
    sum -= (u[i].second - u[i].first) * 2;
    ret = min(ret, sum + t - u[i].first);
  }
  return ret;
}
int main() {
  scanf("%d%d%s", &n, &m, s);
  while (n && s[n - 1] == '.') n--;
  int need = count(s, s + n, 'H');
  int shop = count(s, s + n, 'S');
  int lo = max(need - shop, 0), hi = need;
  while (lo < hi) {
    int x = (lo + hi) / 2;
    if (gao(x) <= m)
      hi = x;
    else
      lo = x + 1;
  }
  if (lo > need) lo = -1;
  if (lo == need && gao(lo) > m) lo = -1;
  printf("%d\n", lo);
}
