#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500500;
const int INF = 1000000009;
int n, t;
string s;
int houses = 0, shops = 0;
int hh[MAXN], ss[MAXN];
void readData() {
  cin >> n >> t;
  cin >> s;
  for (int i = 0; i < (n); ++i) {
    if (s[i] == 'H') {
      houses++;
      hh[i]++;
    } else if (s[i] == 'S') {
      shops++;
      ss[i]++;
    }
    if (i > 0) {
      hh[i] += hh[i - 1];
      ss[i] += ss[i - 1];
    }
  }
}
int mtime(int candy) {
  int lasth = INF;
  int needed = 0;
  int visited = 0;
  int res = 0;
  int resadd = 0;
  for (int i = 0; i < (n); ++i) {
    if (needed == 0) {
      if (s[i] == 'H') {
        resadd = i;
        if (candy == 0) {
          lasth = i;
          needed++;
        } else {
          candy--;
          visited++;
        }
      } else if (s[i] == 'S') {
        candy++;
      }
    } else {
      if (s[i] == 'H') {
        needed++;
        resadd = i;
      } else if (s[i] == 'S') {
        candy++;
        if (candy == needed) {
          resadd = i;
          visited += needed;
          needed = 0;
          candy = 0;
          if (visited < houses) {
            res += 2 * (i - lasth);
          } else {
            res += (i - lasth);
            return res + resadd + 1;
          }
        }
      }
    }
  }
  return res + resadd + 1;
}
int smtime(int candy) {
  int stop(-1);
  if (candy + shops < houses) return INF;
  for (int i = 0; i < (n); ++i) {
    if (candy == 0) {
      if (s[i] == 'H') {
        stop = i;
        break;
      }
    }
    if (s[i] == 'H') {
      --candy;
    } else if (s[i] == 'S') {
      ++candy;
    }
    if (i == n - 1) return n;
  }
  int j(stop), cnt(0);
  for (int j = stop; j <= (n - 1); ++j) {
    if (s[j] == 'H')
      --cnt;
    else if (s[j] == 'S')
      ++cnt;
    if (cnt == 0 && hh[j] == houses) return j + 1 + (j - stop);
  }
  return INF;
}
int main() {
  readData();
  int l = max(0, houses - shops);
  int p = houses;
  int mid;
  if (mtime(houses) > t) {
    cout << -1 << endl;
    return 0;
  }
  while (l < p) {
    mid = (l + p) / 2;
    if (min(smtime(mid), mtime(mid)) > t) {
      l = mid + 1;
    } else {
      p = mid;
    }
  }
  cout << l << endl;
}
