#include <bits/stdc++.h>
using namespace std;
bool can(string& s, int have, int T, const vector<int>& stores,
         const vector<int>& houses) {
  bool need_to_came_back = false;
  int house_to_came_back = -1;
  int mint = 2 * s.size();
  int cur_time = 0;
  int last_imp_store = houses.size() - have - 1;
  if (last_imp_store < 0) {
    mint = houses[houses.size() - 1] + 1;
    return (mint <= T);
  }
  int last_object_to_visit =
      max(stores[last_imp_store], houses[houses.size() - 1]);
  for (int pos = 0; pos <= last_object_to_visit; ++pos) {
    ++cur_time;
    switch (s[pos]) {
      case 'H':
        have--;
        if (have < 0 && !need_to_came_back) {
          need_to_came_back = true;
          house_to_came_back = pos;
        }
        break;
      case 'S':
        have++;
        if (have >= 0 && need_to_came_back) {
          int tmp =
              cur_time + 2 * last_object_to_visit - pos - house_to_came_back;
          mint = min(mint, tmp);
          cur_time += 2 * (pos - house_to_came_back);
          need_to_came_back = false;
        }
        break;
    }
  }
  mint = min(mint, cur_time);
  return (mint <= T);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, T;
  cin >> n >> T;
  string s;
  cin >> s;
  int houses = 0, stores = 0;
  vector<int> ss;
  vector<int> h;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'H') {
      houses++;
      h.push_back(i);
    }
    if (s[i] == 'S') {
      stores++;
      ss.push_back(i);
    }
  }
  if (T <= h[h.size() - 1]) {
    cout << -1 << endl;
    return 0;
  }
  int left = max(0, houses - stores);
  int right = houses;
  while (left < right) {
    int x = (left + right) / 2;
    if (can(s, x, T, ss, h))
      right = x;
    else
      left = x + 1;
  }
  cout << left << endl;
  return 0;
}
