#include <bits/stdc++.h>
using namespace std;
char road[500001];
int numofhouse = 0;
int numofshop = 0;
bool check(int k, int n, int t) {
  int left = numofhouse;
  vector<int> a;
  vector<int> b;
  bool goodend = false;
  int end;
  for (int i = 0; i < n; i++) {
    if (road[i] == 'S') {
      k++;
      if (k == 0) {
        b.push_back(i);
      }
      if (left == 0 && k == 0) {
        end = i;
        break;
      }
    } else if (road[i] == 'H') {
      k--;
      left--;
      if (left == 0 && k >= 0) {
        goodend = true;
        end = i;
        break;
      }
      if (k == -1) {
        a.push_back(i);
      }
    }
  }
  if (a.size() == 0)
    return (end + 1) <= t;
  else {
    int mintime = end + 1 + end - a[0];
    int doubletime = 0;
    for (int i = 1; i < a.size(); i++) {
      doubletime += 2 * (b[i - 1] - a[i - 1]);
      int temp = end + 1 + end - a[i] + doubletime;
      if (temp < mintime) mintime = temp;
    }
    doubletime += 2 * (b[a.size() - 1] - a[a.size() - 1]);
    if (goodend) {
      int temp = end + 1 + doubletime;
      if (temp < mintime) mintime = temp;
    }
    if (mintime <= t)
      return true;
    else
      return false;
  }
}
int main() {
  int n, t;
  cin >> n >> t >> road;
  numofhouse = 0;
  numofshop = 0;
  for (int i = 0; i < n; i++) {
    if (road[i] == 'H')
      numofhouse++;
    else if (road[i] == 'S')
      numofshop++;
  }
  int left = numofshop >= numofhouse ? 0 : numofhouse - numofshop;
  int right = numofhouse;
  while (left < right) {
    int mid = (left + right) >> 1;
    bool ok = check(mid, n, t);
    if (ok) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  if (check(left, n, t))
    cout << left << endl;
  else
    cout << -1 << endl;
}
