#include <bits/stdc++.h>
#pragma comment(linker, "/stack:128000000")
using namespace std;
const int INF = 1000000000;
const long long LINF = 4000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
char s[500100];
int n, t;
int dp[500100];
bool read() {
  scanf("%d%d", &n, &t);
  scanf("%s", s);
  return false;
}
int get(int start, int cs, int &lasth) {
  if (dp[start] >= 0) return dp[start];
  int ch = 0, fh = -1;
  int cnt = 0;
  int curLastH = -1;
  for (int i = start; i < n; i++) {
    cnt++;
    if (s[i] == '.') continue;
    if (s[i] == 'H') {
      ch++;
      if (fh < 0 && ch > cs) fh = i;
      curLastH = i;
    } else if (s[i] == 'S')
      cs++;
    if (ch == cs) {
      int tt = get(i + 1, 0, lasth);
      if (lasth < 0) {
        lasth = i;
        int r = cnt + (i - (fh < 0 ? lasth : fh));
        return dp[start] = r;
      } else {
        if (fh < 0) return dp[start] = cnt + tt;
        int r1 = cnt + (i - fh) * 2 + tt;
        int r2 = fh - start + (lasth - fh) * 2 + 1;
        return dp[start] = min(r1, r2);
      }
    }
  }
  lasth = curLastH;
  return dp[start] = max(0, curLastH - start + 1);
}
bool check(int init) {
  memset((dp), (-1), sizeof(dp));
  int lasth;
  int c = get(0, init, lasth);
  return c <= t;
}
void solve() {
  int ch = 0, cs = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H')
      ch++;
    else if (s[i] == 'S')
      cs++;
  }
  int lb = max(0, ch - cs);
  int rb = ch;
  while (rb - lb > 1) {
    int mid = (lb + rb) >> 1;
    if (check(mid))
      rb = mid;
    else
      lb = mid;
  }
  if (check(lb))
    printf("%d\n", lb);
  else if (check(rb))
    printf("%d\n", rb);
  else
    printf("-1\n");
}
void gen() {
  n = 500000;
  t = n;
  for (int i = 0; i < n; i++) {
    int x = rand() % 3;
    if (x == 0)
      s[i] = 'H';
    else if (x == 1)
      s[i] = 'S';
    else
      s[i] = '.';
  }
}
int main() {
  prepare();
  int ntests = 1;
  for (int i = (0); i < (((ntests))); i++) {
    read();
    solve();
  }
  return 0;
}
