#include <bits/stdc++.h>
#pragma comment(linker, "/stack:102400000,102400000")
using namespace std;
const double PI = acos(-1.0);
template <class T_T>
T_T f_max(T_T a, T_T b) {
  return a > b ? a : b;
}
template <class T_T>
T_T f_min(T_T a, T_T b) {
  return a < b ? a : b;
}
template <class T_T>
T_T f_abs(T_T a) {
  return a > 0 ? a : -a;
}
template <class T_T>
T_T gcd(T_T a, T_T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T_T>
void swap(T_T *a, T_T *b) {
  T_T c;
  c = a;
  a = b;
  b = c;
}
int n, m;
int ss, hh, loc;
char str[600001];
int loc_h[600001];
int loc_s[600001];
bool judge(int p) {
  int i, j, k, ph, ps, pt, temp;
  if (p + ss < hh) return false;
  if (m >= 2 * n) return true;
  k = pt = 0;
  for (i = p, j = 0; i < hh; i++, j++) {
    if (loc_s[j] < loc_h[i]) {
      continue;
    } else {
      temp = loc_s[j] - loc_h[i];
      if (pt == 0) {
        ph = loc_h[i], ps = loc_s[j], pt = temp;
      } else {
        if (pt <= loc_h[i] - ps) {
          k += 2 * pt;
          ph = loc_h[i], ps = loc_s[j], pt = temp;
        } else {
          ps = loc_s[j];
          pt = ps - ph;
        }
      }
    }
  }
  if (pt == 0)
    temp = loc_h[hh - 1] + 1;
  else if (ps > loc_h[hh - 1]) {
    temp = ps + 1 + k + pt;
  } else {
    temp = loc_h[hh - 1] + 1 + k + f_min(pt * 2, loc_h[hh - 1] - ph);
  }
  return temp <= m;
}
int find(int l, int r) {
  int mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (judge(mid))
      r = mid;
    else
      l = mid + 1;
  }
  return l;
}
int main() {
  int q, w, e, r;
  int i, j, k;
  int t;
  while (~scanf("%d%d", &n, &m)) {
    scanf("%s", str);
    ss = hh = 0;
    for (i = 0; i < n; i++) {
      if (str[i] == 'H') {
        loc_h[hh++] = i;
        loc = i + 1;
      }
      if (str[i] == 'S') loc_s[ss++] = i;
    }
    if (loc > m) {
      printf("-1\n");
    } else {
      printf("%d\n", find(0, hh));
    }
  }
  return 0;
}
