#include <bits/stdc++.h>
using namespace std;
bool isPossibleWithK(string &street, int sweets, int T) {
  vector<int> extraTime;
  vector<int> points;
  int K = 0;
  int lastPoint;
  for (int i = 0; i < street.size(); i++) {
    if (sweets < 0) lastPoint = i + 1;
    if (street[i] == 'S') sweets++;
    if (street[i] == 'H') {
      sweets--;
      lastPoint = i + 1;
    }
    if (street[i] == 'H' && sweets == -1) {
      extraTime.push_back(0);
      points.push_back(i);
      K++;
    }
    if (sweets < 0) {
      extraTime[K - 1]++;
    }
  }
  T -= lastPoint;
  int minimumTime = 1 << 30;
  int sumTime = 0;
  for (int i = 0; i < K; i++) {
    minimumTime = min(minimumTime, lastPoint - points[i] - 1 + sumTime);
    sumTime += extraTime[i] * 2;
  }
  T -= min(minimumTime, sumTime);
  extraTime.clear();
  points.clear();
  if (K == 0 && T >= 0) return true;
  if (T < 0) return false;
  return true;
}
int main() {
  int N, T;
  cin >> N >> T;
  string street;
  cin >> street;
  int sweets = 0;
  for (int i = 0; i < street.size(); i++) {
    if (street[i] == 'H') sweets++;
    if (street[i] == 'S') sweets--;
  }
  int begin = max(sweets, 0), end = street.size(), medium;
  while (begin < end) {
    medium = (begin + end) / 2;
    if (isPossibleWithK(street, medium, T))
      end = medium;
    else
      begin = medium + 1;
  }
  if (!isPossibleWithK(street, begin, T))
    cout << -1 << endl;
  else
    cout << begin << endl;
  return 0;
}
