#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, t;
char a[N];
deque<int> dq;
pair<int, int> v[N], v2[N];
bool check(int k) {
  int cost = 0, m = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 'H') dq.push_back(i);
  }
  for (int i = 1; i <= n && !dq.empty(); ++i) {
    ++cost;
    if (a[i] == 'S') ++k;
    if (dq.front() <= i && k > 0) {
      v[++m] = {dq.front(), i};
      while (k > 0 && !dq.empty() && dq.front() <= i) {
        dq.pop_front();
        --k;
      }
    }
  }
  if (!dq.empty()) {
    while (!dq.empty()) dq.pop_front();
    return false;
  }
  int st = v[1].first;
  int aux = 0;
  int sum = 0;
  for (int i = 2; i <= m; ++i) {
    if (v[i].first > v[i - 1].second) {
      v2[++aux] = {st, v[i - 1].second};
      sum += 2 * (v[i - 1].second - st);
      st = v[i].first;
    }
  }
  v2[++aux] = {st, v[m].second};
  sum += 2 * (v[m].second - st);
  int r = sum, dr = v[m].second;
  for (int i = aux; i; --i) {
    if (r > sum - 2 * (v2[i].second - v2[i].first) + dr - v2[i].first) {
      r = sum - 2 * (v2[i].second - v2[i].first) + dr - v2[i].first;
      dr = v2[i].first;
    }
  }
  cost += r;
  return cost <= t;
}
int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int st = 0, dr = n, mij, ans = -1;
  while (st <= dr) {
    mij = (st + dr) / 2;
    if (check(mij)) {
      dr = mij - 1;
      ans = mij;
    } else
      st = mij + 1;
  }
  cout << ans;
  return 0;
}
