#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int n, m, q, p;
int A[501234];
char S[501234];
int calc(int s) {
  int i, j, k;
  k = 0;
  int r, rr;
  r = rr = 0;
  for (i = (0); i < (n); ++i) {
    r = min(r, rr) + 2;
    if (s >= k)
      ++rr;
    else
      rr += 3;
    if (S[i] == 'S') ++s;
    if (S[i] == 'H') ++k;
    if (i >= p && s >= k) break;
  }
  if (s < k) return 1012345678;
  return min(r, rr);
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    scanf(
        "%"
        "d",
        &(m));
    scanf(
        "%"
        "s",
        &(S));
    p = -1;
    for (i = (0); i < (n); ++i)
      if (S[i] == 'H') p = i;
    int l = -1, r = n + 1, mid;
    for (; l + 1 < r;) {
      mid = (l + r) / 2;
      if (calc(mid) <= m)
        r = mid;
      else
        l = mid;
    }
    int res = r;
    if (res == n + 1) res = -1;
    printf(
        "%"
        "d",
        (res));
    printf("\n"), firstout = 1;
  }
  return 0;
}
