#include <bits/stdc++.h>
using namespace std;
string second;
long long needed;
long long lasts;
long long n, t;
vector<long long> vk;
long long cnth;
long long calc(long long k) {
  int last = 0;
  long long cur = 0;
  long long left = max((cnth - k), 0LL);
  0;
  ;
  long long finals = vk[left];
  0;
  ;
  long long ans = (2 * n);
  for (int i(0), ThkMk(n); i < ThkMk; ++i) {
    if (k >= 0) last = i;
    if (second[i] == 'S') {
      ++k;
      if (k == 0) {
        0;
        ;
        cur += (i - last) * 2;
        last = i;
      }
    }
    if (second[i] == 'H') {
      if (k == 0) {
        last = i;
      }
      --k;
      long long l = (i - last);
      if (last == -1) l = 0;
      long long r = max(finals, needed);
      long long rr = max(0LL, r - i);
      long long nw = cur + (rr * 2) + l;
      if (i == 32) {
        0;
        ;
        0;
        ;
        0;
        ;
        0;
        ;
      }
      ans = min(ans, nw);
    }
    ++cur;
  }
  return ans;
}
bool ok(long long u) { return calc(u) <= t; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t >> second;
  --t;
  vk.push_back(0);
  long long cnt = 0;
  for (int i(0), ThkMk(n); i < ThkMk; ++i) {
    if (second[i] == 'H') {
      needed = i;
      --cnt;
      ++cnth;
    }
    if (second[i] == 'S') {
      lasts = i;
      vk.push_back(i);
      ++cnt;
    }
  }
  if (needed > t) {
    cout << -1 << '\n';
    ;
    return 0;
  }
  cnt = min(cnt, 0LL);
  cnt = abs(cnt);
  0;
  ;
  if (ok(cnt)) {
    cout << cnt << '\n';
    ;
    0;
    ;
    return 0;
  }
  long long ans = cnt;
  for (int i = 1e6; i > 0; i /= 2) {
    while (!ok(ans + i)) ans += i;
  }
  cout << ans + 1 << '\n';
  ;
  return 0;
}
