#include <bits/stdc++.h>
using namespace std;
long long minTime(string s, int k) {
  int lastH = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'H') {
      lastH = i;
    }
  }
  for (int i = 0; i < s.length(); i++) {
    if (k > 0 && s[i] == 'H') {
      s[i] = '.';
      k--;
    }
  }
  int H = 0;
  vector<int> pos;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'H') {
      lastH = i;
      if (H == 0) {
        pos.push_back(i);
      }
      H++;
    } else if (s[i] == 'S') {
      H--;
      if (H == 0) {
        pos.push_back(i);
      }
    }
  }
  if (H > 0) {
    return 2e9;
  }
  if (pos.size() != 0) lastH = max(lastH, pos[pos.size() - 1]);
  pos.push_back(lastH);
  pos.push_back(lastH);
  int res = 2e9;
  int used = 0;
  for (int i = 0; i < pos.size(); i += 2) {
    if (i == 0) {
      used += pos[i] + 1;
    } else {
      used += pos[i] - pos[i - 2];
    }
    res = min(res, used + (lastH - pos[i]) * 2);
    used += (pos[i + 1] - pos[i]) * 2;
  }
  return res;
}
int main() {
  for (int i = 0; i < 1000; i++) {
    minTime("...HHHSSS...S..H", i);
  }
  long long n, t;
  cin >> n >> t;
  string s;
  cin >> s;
  long long l = -1, r = 1e8;
  while (l + 1 != r) {
    long long mid = (l + r) / 2;
    if (minTime(s, mid) <= t) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (minTime(s, r) > t || r > 1e7) {
    cout << -1 << endl;
  } else
    cout << r << endl;
}
