#include <bits/stdc++.h>
using namespace std;
const int maxn = 500500;
int n, t;
int maxh;
int total;
char a[maxn];
int nh[maxn];
bool check(int cur) {
  int ctime = t;
  int passed_houses = 0;
  int first = -1, last = -1;
  for (int i = 0; i <= maxh; ++i) {
    --ctime;
    if (a[i] == 'H') {
      if (cur) {
        --cur;
      } else {
        ++passed_houses;
        if (first == -1) {
          first = i;
        }
        last = i;
      }
    } else if (a[i] == 'S') {
      ++cur;
      if (cur == passed_houses && (ctime < 2 * (maxh - i))) {
        cur -= passed_houses;
        passed_houses = 0;
        ctime -= 2 * (i - first);
        first = last = -1;
      }
    }
  }
  int pos = maxh;
  while (pos + 1 < n && cur < passed_houses) {
    ++pos;
    --ctime;
    if (a[pos] == 'S') ++cur;
  }
  if (first >= 0) {
    ctime -= (pos - first);
  }
  return cur >= passed_houses && ctime >= 0;
}
int main(int argc, char **argv) {
  scanf("%d %d\n%s", &n, &t, a);
  int ph = -1;
  for (int i = 0; i < n; ++i)
    if (a[i] == 'H') {
      ++total;
      maxh = i;
      if (ph >= 0) {
        nh[ph] = i;
      }
      ph = i;
    }
  int l = 0, r = 2 * maxn;
  while (l < r) {
    int m = (l + r) >> 1;
    if (check(m)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  if (check(l)) {
    cout << l << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
