#include <bits/stdc++.h>
using namespace std;
char S[500000];
int Sum[500001], Next[500000], Jump[500000];
bool Solve(int Sweet, int N, int Time, int Far) {
  int P = 0;
  while (Time >= 0 && P < Far) {
    Time--;
    if (S[P] == 'S')
      Sweet++;
    else if (S[P] == 'H' && Sweet)
      Sweet--;
    else if (S[P] == 'H') {
      if (Jump[P] != -1) {
        int Temp = 2 * (Jump[P] - P - 1);
        if (Time >= Temp) return true;
      }
      Time -= 3 * (Next[P] - P - 1);
      P = Next[P] - 1;
    }
    P++;
  }
  return Time >= 0;
}
int main() {
  int N, Time;
  scanf("%d%d", &N, &Time);
  int Shop = 0, House = 0, Far = 0;
  for (int i = 0; i < N; i++) {
    while (S[i] = getchar(), S[i] != 'S' && S[i] != 'H' && S[i] != '.')
      ;
    if (S[i] == 'S') Shop++;
    if (S[i] == 'H') {
      House++;
      Far = i + 1;
    }
  }
  if (Time < Far) {
    printf("-1\n");
    return 0;
  }
  memset(Sum, 0, sizeof(Sum));
  for (int i = Sum[0] = 0; i < N; i++) {
    Sum[i + 1] = Sum[i];
    if (S[i] == 'S') Sum[i + 1]++;
    if (S[i] == 'H') Sum[i + 1]--;
  }
  static int Mark[1000001];
  memset(Mark, -1, sizeof(Mark));
  for (int i = N; i >= 0; i--) {
    Next[i] = Mark[Sum[i] + 500000];
    Mark[Sum[i] + 500000] = i;
  }
  memset(Mark, -1, sizeof(Mark));
  for (int i = N; i >= 0; i--) {
    Jump[i] = Mark[Sum[i] + 500000];
    if (i >= Far) Mark[Sum[i] + 500000] = i;
  }
  int Left = max(0, House - Shop), Right = House;
  while (Left < Right) {
    int Mid = (Left + Right) / 2;
    if (Solve(Mid, N, Time, Far))
      Right = Mid;
    else
      Left = Mid + 1;
  }
  printf("%d\n", Left);
  return 0;
}
