#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int numShops, numHouses, farthestHouse;
bool done[500013];
int nextHouse[500013];
int getTime(int k) {
  for (int i = 0; i < n; i++) {
    done[i] = false;
  }
  for (int i = 0; i < n; i++) {
    nextHouse[i] = 1000000001;
  }
  int candyCount = 0;
  int rightpoint = farthestHouse;
  for (int i = 0; i < n; i++) {
    if (s[i] != 'H') continue;
    for (int j = i; j >= 0; j--) {
      if (j != i && s[j] == 'H') break;
      nextHouse[j] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') {
      candyCount++;
    }
    if (candyCount == numHouses - k) {
      rightpoint = max(rightpoint, i);
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (nextHouse[i] == 1000000001) nextHouse[i] = rightpoint;
  }
  int neededCandies = numHouses;
  int totalAnswer = 1000000001;
  int answer = 0;
  int current = 0;
  int earliestUndone = 1000000001;
  int countUndone = 0;
  for (int i = 0; i <= rightpoint; i++) {
    if (s[i] == 'H') {
      earliestUndone = min(earliestUndone, i);
      countUndone++;
    } else if (s[i] == 'S') {
      k++;
    }
    if (countUndone <= k) {
      if (earliestUndone != 1000000001) {
        answer += (i - earliestUndone) * 2;
        earliestUndone = 1000000001;
        k -= countUndone;
        countUndone = 0;
      }
    }
    answer++;
    int back = min(earliestUndone, nextHouse[i]);
    int thisAnswer = answer + rightpoint - i + rightpoint -
                     min(earliestUndone, nextHouse[i]);
    totalAnswer = min(totalAnswer, thisAnswer);
  }
  return totalAnswer;
}
int main() {
  if (fopen("FILENAME.in", "r")) {
    freopen("FILENAME.in", "r", stdin);
    freopen("FILENAME.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> t;
  cin >> s;
  for (int i = 0; i < n; i++) {
  }
  for (int i = 0; i < n; i++) {
    numShops += s[i] == 'S';
    numHouses += s[i] == 'H';
    farthestHouse = max(farthestHouse, (s[i] == 'H' ? i : 0));
  }
  if (farthestHouse + 1 > t) {
    cout << "-1" << endl;
    return 0;
  }
  int start = max(0, numHouses - numShops);
  int end = numHouses;
  while (start <= end) {
    int mid = (start + end) / 2;
    int time = getTime(mid);
    if (time <= t) {
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  cout << start << endl;
}
