#include <bits/stdc++.h>
char a[500010];
int solve(char *a, int n, int t, int k) {
  int tt = 0;
  int tk = k;
  int flag = 1;
  int index1 = -1;
  int index2 = -1;
  int count1 = 0;
  int count2 = 0;
  int count3 = 0;
  int count4 = 0;
  int i;
  for (i = 0; i < n; i++) {
    if (a[i] == 'H') count3 = count3 + 1;
  }
  for (i = 0; i < n; i++) {
    if (a[i] == '.') tt = tt + 1;
    if (a[i] == 'H') {
      tt = tt + 1;
      tk = tk - 1;
      count4 = count4 + 1;
      if ((tk < 0) && (flag == 1)) {
        index1 = i;
        flag = 0;
      }
      if (tk < 0) {
        count1 = count1 + 1;
      }
    }
    if (a[i] == 'S') {
      tt = tt + 1;
      tk = tk + 1;
      if (count1 > 0) count2 = count2 + 1;
    }
    if (((count4 == count3) && (tk >= 0)) || (i == n - 1)) {
      index2 = i;
      break;
    }
    if (count1 && count2 && (count1 == count2)) {
      if ((i - index1) < (n - 1 - i)) {
        tt = tt + 2 * (i - index1);
        count1 = 0;
        count2 = 0;
        index1 = -1;
        flag = 1;
      }
    }
  }
  if (index1 >= 0) {
    tt = tt + index2 - index1;
  }
  if ((tt > t) || (tk < 0)) return 0;
  return 1;
}
int binary_search(char *a, int n, int t) {
  int p = 0;
  int r = n;
  int k = (p + r) / 2;
  while (1) {
    if (solve(a, n, t, k) == 1) {
      if (k == 0) {
        return k;
      } else {
        if (solve(a, n, t, k - 1) == 0)
          return k;
        else
          r = k - 1;
      }
    } else {
      if (solve(a, n, t, k + 1) == 0)
        p = k + 1;
      else
        return k + 1;
    }
    k = (p + r) / 2;
  }
}
int main() {
  int i, n, t;
  scanf("%d%d", &n, &t);
  getchar();
  for (i = 0; i < n; i++) {
    scanf("%c", &a[i]);
  }
  if (solve(a, n, t, n) == 0)
    printf("-1\n");
  else
    printf("%d\n", binary_search(a, n, t));
  return 0;
}
