#include <bits/stdc++.h>
using namespace std;
int nextInt() {
  int n;
  cin >> n;
  return n;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n, t;
  cin >> n >> t;
  string s;
  cin >> s;
  int hs = 0;
  int ss = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'S') ++ss;
    if (s[i] == 'H') {
      if (i >= t) {
        cout << -1 << "\n";
        return 0;
      }
      ++hs;
    }
  }
  int l = 0;
  if (hs > ss) l = hs - ss;
  int r = hs;
  while (l < r) {
    int m = (l + r) >> 1;
    int curr = 0;
    int sw = m;
    int hPassed = 0;
    int sPassed = 0;
    vector<int> emptyH;
    int ans = 0;
    int last = 0;
    vector<pair<int, int>> undo;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'H') {
        ++hPassed;
        if (sw)
          --sw;
        else
          emptyH.push_back(i);
      }
      if (s[i] == 'S') {
        ++sPassed;
        if (emptyH.empty())
          ++sw;
        else {
          if (emptyH.size() == 1) {
            undo.push_back(make_pair(i, i - emptyH[0]));
            ans += 2 * (i - emptyH[0]);
          }
          emptyH.pop_back();
        }
      }
      if (hPassed == hs && sPassed + m >= hs) {
        last = i;
        ans += i + 1;
        break;
      }
    }
    for (auto it = undo.rbegin(); it != undo.rend(); ++it) {
      if (it->second >= last - it->first) {
        ans = ans + last - it->first - it->second;
        last = it->first - it->second;
      } else
        break;
    }
    if (ans <= t)
      r = m;
    else
      l = m + 1;
  }
  cout << l << "\n";
}
