#include <bits/stdc++.h>
using namespace std;
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
template <class T>
void uniq(vector<T>& c) {
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
}
template <class T>
string to_s(const T& a) {
  ostringstream os;
  os << a;
  return os.str();
}
template <class T>
T to_T(const string& s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  os << "( " << p.first << ", " << p.second << " )";
  return os;
}
template <class T>
void print(T a, int n, const string& deli = " ", int br = 1) {
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 != n) cout << deli;
  }
  while (br--) cout << endl;
}
template <class T>
void print(const T& c, const string& deli = " ", int br = 1) {
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) {
    cout << *it;
    if (++it != c.end()) cout << deli;
    --it;
  }
  while (br--) cout << endl;
}
template <class T>
void print2d(T a, int w, int h, int width = -1, int br = 1) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (width != -1) cout.width(width);
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  while (br--) cout << endl;
}
template <class T>
void input(T& a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
template <class T>
void input(T* a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
void fast_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
bool valid(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const double PI = acos(-1.0);
const int mod = ((long long)(1e9)) + 7;
int n, t;
int num_h, num_s, last_h;
string s;
int las_pos(int init) {
  int sw = init;
  for (int i = 0; i < (int)(n); ++i) {
    if (s[i] == 'S') ++sw;
    if (sw >= num_h) return max(i, last_h);
  }
  (cout << "init"
        << ": " << (init) << endl);
  exit(1);
}
bool ok(int init) {
  if (init + num_s < num_h) return false;
  int last_pos = las_pos(init);
  int left = -1;
  int sw = init;
  int step = 0;
  for (int i = 0; i < (int)(n); ++i) {
    ++step;
    if (s[i] == 'H') {
      if (left == -1 && sw == 0) {
        left = i;
        if (step + 2 * (last_pos - i) <= t) return true;
      }
      --sw;
    } else if (s[i] == 'S') {
      ++sw;
      if (left != -1 && sw == 0) {
        step += 2 * (i - left);
        left = -1;
      }
    }
    if (i == last_pos) break;
  }
  return step <= t;
}
int main() {
  cin >> n >> t >> s;
  num_h = count((s).begin(), (s).end(), 'H');
  num_s = count((s).begin(), (s).end(), 'S');
  last_h = s.find_last_of('H');
  const int imp = num_h + 1;
  int low = -1, high = imp;
  while (high - low > 1) {
    int mid = (low + high) / 2;
    if (ok(mid))
      high = mid;
    else
      low = mid;
  }
  int res = high == imp ? -1 : high;
  cout << res << endl;
}
