#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long double PI = 3.1415926535897932384626433832795;
string s;
int a[500020], ac;
int n, T, q, fh;
bool ok(int x) {
  int c = x, ti = 0, nd = 0, bk = 0, md = 0, fr = fh;
  if (x + ac < q) return 0;
  if (x < q) fr = max(fr, a[q - x - 1]);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') {
      c++;
      if (nd != 0) {
        if (c >= nd) {
          c -= nd;
          if (ti + fr - i + fr - bk <= T) return 1;
          ti += 2 * (i - bk);
          md += nd;
          nd = 0;
          if (ti > T) break;
        }
      }
    } else if (s[i] == 'H') {
      if (c) {
        c--;
        md++;
      } else {
        if (nd == 0) {
          nd++;
          bk = i;
        } else
          nd++;
      }
    }
    if (md == q) break;
    ti++;
  }
  if (nd) return 0;
  return ti <= T;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> T >> s;
  T--;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'H') {
      q++;
      fh = i;
    } else if (s[i] == 'S')
      a[ac++] = i;
  }
  int l = 0, r = n + 5;
  while (l < r) {
    int m = (l + r) >> 1;
    if (ok(m))
      r = m;
    else
      l = m + 1;
  }
  if (l == n + 5)
    cout << -1 << '\n';
  else
    cout << l << '\n';
  return 0;
}
