#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <class T>
inline T max1(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T min1(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T gcd1(T a, T b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd1(b, a % b);
}
template <class T>
inline T lb(T num) {
  return num & (-num);
}
inline int bitnum(unsigned long long nValue) {
  nValue = ((0xaaaaaaaaaaaaaaaaull & nValue) >> 1) +
           (0x5555555555555555ull & nValue);
  nValue = ((0xccccccccccccccccull & nValue) >> 2) +
           (0x3333333333333333ull & nValue);
  nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue) >> 4) +
           (0x0f0f0f0f0f0f0f0full & nValue);
  nValue = ((0xff00ff00ff00ff00ull & nValue) >> 8) +
           (0x00ff00ff00ff00ffull & nValue);
  nValue = ((0xffff0000ffff0000ull & nValue) >> 16) +
           (0x0000ffff0000ffffull & nValue);
  nValue = ((0xffffffff00000000ull & nValue) >> 32) +
           (0x00000000ffffffffull & nValue);
  return nValue;
}
long long pow(long long n, long long m, long long mod = 0) {
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
const int maxn = 1000000;
char str[maxn];
int n, ns, nh, t;
int loc[maxn][2];
int dp[maxn][2][2];
bool judge(int orig) {
  dp[orig][0][0] = dp[orig][1][0] = loc[orig][0];
  dp[orig][0][1] = dp[orig][1][1] = loc[orig][0];
  for (int i = orig + 1; i <= nh; i++) {
    if (loc[i - orig][1] < loc[i][0]) {
      dp[i][0][0] = dp[i - 1][0][0] + loc[i][0] - dp[i - 1][0][1];
      dp[i][0][1] = loc[i][0];
      dp[i][1][0] = min1(dp[i - 1][0][0] + loc[i][0] - dp[i - 1][0][1],
                         dp[i - 1][1][0] + 2 * (loc[i][0] - dp[i - 1][1][1]));
      dp[i][1][1] = loc[i][0];
    } else {
      dp[i][0][0] = dp[i - 1][0][0] + max1(0, loc[i][0] - dp[i - 1][0][1]) +
                    3 * (loc[i - orig][1] - max1(loc[i][0], dp[i - 1][0][1]));
      dp[i][0][1] = loc[i - orig][1];
      dp[i][1][0] =
          min1(dp[i - 1][0][0] + loc[i][0] - dp[i - 1][0][1] +
                   2 * (loc[i - orig][1] - max1(loc[i][0], dp[i - 1][0][1])),
               dp[i - 1][1][0] + 2 * (loc[i - orig][1] - dp[i - 1][1][1]));
      dp[i][1][1] = loc[i - orig][1];
    }
  }
  if (min1(dp[nh][0][0], dp[nh][1][0]) <= t) return 1;
  return 0;
}
int main() {
  scanf("%d%d%s", &n, &t, str);
  for (int i = 0; i < n; i++) {
    if (str[i] == 'H') loc[++nh][0] = i + 1;
    if (str[i] == 'S') loc[++ns][1] = i + 1;
  }
  int be = max1(0, nh - ns), en = nh;
  while (be < en) {
    int mid = (be + en) / 2;
    if (judge(mid))
      en = mid;
    else
      be = mid + 1;
  }
  if (!judge(be))
    cout << -1 << endl;
  else
    cout << be << endl;
  return 0;
}
