#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
const double PI = 3.1415926535897932384626433832795;
template <class T>
T min(T &a, T &b) {
  return (a < b) ? a : b;
}
template <class T>
T max(T &a, T &b) {
  return (a > b) ? a : b;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T abs(T &a) {
  return (a < 0) ? (-a) : a;
}
inline void read(int &x) { scanf("%d", &x); }
inline void readln(int &x) { scanf("%d\n", &x); }
inline void write(int x) { printf("%d", x); }
inline void writeln(int x) { printf("%d\n", x); }
inline void read(long long &x) { scanf("%lld", &x); }
inline void readln(long long &x) { scanf("%lld\n", &x); }
inline void write(long long x) { printf("%lld", x); }
inline void writeln(long long x) { printf("%lld\n", x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void readln(double &x) { scanf("%lf\n", &x); }
inline void write(double x) { printf("%.15lf", x); }
inline void writeln(double x) { printf("%.15lf\n", x); }
inline void read(char *s) { scanf("%s", s); }
inline void readln(char *s) { scanf("%s\n", s); }
inline void write(char *s) { printf("%s", s); }
inline void writeln(char *s) { printf("%s\n", s); }
inline int readInt() {
  int x;
  read(x);
  return x;
}
inline long long readLong() {
  long long x;
  read(x);
  return x;
}
inline double readDouble() {
  double x;
  read(x);
  return x;
}
inline void showTime() {}
int n;
int t;
string s;
int lh;
int sc[1000007];
int hc[1000007];
int cnts(int a, int b) {
  if (b >= n) b = n - 1;
  return sc[b + 1] - sc[a];
}
int cnth(int a, int b) {
  if (b >= n) b = n - 1;
  return hc[b + 1] - hc[a];
}
bool good(int k) {
  int curt = t;
  int leftest = -1;
  for (int i = 0; i <= lh; i++) {
    --curt;
    if (k < 0) curt -= 2;
    if (curt < 0) return false;
    int maxlen = curt / 2;
    if (i + maxlen >= lh &&
        k + cnts(i, i + maxlen) - cnth(i, i + maxlen) >= 0) {
      return true;
    }
    if (s[i] == 'H') {
      --k;
    } else if (s[i] == 'S') {
      ++k;
    }
  }
  return false;
}
int main() {
  srand((unsigned)time(NULL));
  cin >> n >> t;
  cin >> s;
  for (int i = 0; i < ((int)((s).size())); i++)
    if (s[i] == 'H') lh = i;
  hc[0] = 0;
  sc[0] = 0;
  for (int i = 0; i < ((int)((s).size())); i++) {
    hc[i + 1] = hc[i];
    if (s[i] == 'H') ++hc[i + 1];
    sc[i + 1] = sc[i];
    if (s[i] == 'S') ++sc[i + 1];
  }
  int k = 0;
  int step = (1 << 20);
  while (step) {
    if (!good(k + step)) k += step;
    step >>= 1;
  }
  if (!good(k)) ++k;
  if (k <= n)
    cout << k;
  else
    cout << -1;
}
