#include <bits/stdc++.h>
using namespace std;
char s[500010];
int num[500010];
int cnt;
long long t, mid;
int n;
int skip[500010];
long long minn(long long a, long long b) { return a < b ? a : b; }
stack<int> sta;
int ok(long long k) {
  int i, j, end = -1, last, type = -1, cnt = 0;
  long long time = 0, min;
  for (i = 0; i < n; ++i) {
    ++time;
    if (s[i] == 'H') {
      if (k) {
        --k;
        last = i;
        type = 0;
        continue;
      }
      type = 1;
      if (skip[i] == -1) {
        return 0;
      }
      time += (skip[i] - i) * 3;
      if (end != -1) {
        num[cnt++] = i - end;
      }
      num[cnt++] = skip[i] - i;
      end = skip[i];
      last = skip[i];
      i = skip[i];
    } else if (s[i] == 'S') {
      ++k;
    }
  }
  if (type == 0 && end != -1) {
    num[cnt++] = last - end;
  }
  time -= (n - 1 - last);
  min = time;
  for (i = cnt - 1; i >= 0; --i) {
    if (i & 1) {
      time += num[i];
    } else {
      time -= num[i];
      min = minn(min, time);
    }
  }
  return min <= t;
}
int main() {
  long long left, right;
  int i;
  cin >> n >> t >> s;
  memset(skip, -1, sizeof(skip));
  for (i = 0; i < n; ++i) {
    if (s[i] == 'H') {
      sta.push(i);
    } else if (s[i] == 'S') {
      if (!sta.empty()) {
        skip[sta.top()] = i;
        sta.pop();
      }
    }
  }
  left = 0;
  right = n + 1;
  while (left < right) {
    mid = (left + right) >> 1;
    if (ok(mid))
      right = mid;
    else {
      left = mid + 1;
    }
  }
  if (right == n + 1)
    printf("-1\n");
  else
    cout << left << endl;
  return 0;
}
