#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
int n, t;
string s;
bool f(int mid) {
  int sc = count((s).begin(), (s).end(), 'S') + mid;
  int hc = count((s).begin(), (s).end(), 'H');
  if (sc < hc) return false;
  string temp = s;
  for (int i = (n - 1); i >= (0); --i) {
    if (sc == hc) break;
    if (s[i] == 'S') s[i] = '.', --sc;
  }
  int last = -1;
  int till = -1;
  for (int i = (0); i <= (n - 1); ++i) {
    if (s[i] == 'S') last = i;
    if (s[i] == 'H') till = i;
  }
  vector<int> a(n + 5);
  int prv = -1;
  int shops = mid;
  int ans = 0;
  last = max(last, till);
  for (int i = (0); i <= (last); ++i) {
    ++ans;
    if (s[i] == 'S') {
      ++shops;
      if (shops == 0) {
        if (ans + last - i + last - prv <= t) {
          s = temp;
          return true;
        }
        ans += 2 * (i - prv);
      }
    } else if (s[i] == 'H') {
      --shops;
      if (shops == -1) {
        prv = i;
      }
    }
  }
  s = temp;
  return ans <= t;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> t;
  cin >> s;
  int st = 0, en = n;
  while (st < en) {
    int mid = (st + en) >> 1;
    if (f(mid))
      en = mid;
    else
      st = mid + 1;
  }
  if (not f(st)) st = -1;
  cout << st << "\n";
  return 0;
}
