#include <bits/stdc++.h>
using namespace std;
int ToInt(string& s, int len) {
  int r = 0;
  for (int i = 0, max_ = (len); i < max_; ++i) {
    r *= 10;
    r += s[i] - '0';
  }
  return r;
}
int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * (b / GCD(a, b)); }
long long Pow(long long n, long long e) {
  if (e == 0) return 1;
  if (e == 1)
    return n;
  else if (e & 1) {
    long long t = Pow(n, e / 2);
    return n * t * t;
  } else {
    long long t = Pow(n, e / 2);
    return t * t;
  }
}
char b[500005];
string s;
int N, T, last = 0;
bool OK(int x) {
  int now = x, end = -1;
  for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i) {
    if (s[i] == 'H')
      --now;
    else if (s[i] == 'S')
      ++now;
    if (now >= 0 && i >= last) {
      end = i;
      break;
    }
  }
  now = x;
  if (end == -1) return false;
  int cost = 0, res = 100000000, pre = -1;
  for (int i = 0, max_ = (end + 1); i < max_; ++i) {
    ++cost;
    if (s[i] == 'H') {
      --now;
      if (now == -1) pre = i;
    } else if (s[i] == 'S') {
      ++now;
      if (now == 0) {
        res = min(res, cost + (end - i) + (end - pre));
        cost += 2 * (i - pre);
      }
    }
  }
  res = min(res, cost);
  return res <= T;
}
int main() {
  scanf("%d %d", &N, &T);
  gets(b);
  gets(b);
  s = b;
  for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i)
    if (s[i] == 'H') last = i;
  int minK = 0, maxK = 1000000, currK = 0, res = -1;
  while (minK <= maxK) {
    currK = (minK + maxK) / 2;
    if (OK(currK)) {
      res = currK;
      maxK = currK - 1;
    } else
      minK = currK + 1;
  }
  printf("%d\n", res);
  return 0;
}
