#include <bits/stdc++.h>   using namespace std;   int n, t;   string s;   int puc(int k, int t) {     vector<int> v(n + 1, 0);     v[n - 1] = (s[n - 1] ==  H );     for (int i = n - 2; i >= 0; --i) v[i] = v[i + 1] + (s[i] ==  H );     int nh = 0, ns = 0;     for (int i = 0; i < int(n); ++i) {       if (s[i] ==  H )         ++nh;       else if (s[i] ==  S )         ++ns;     }     if (k + ns < nh) return 0;     int zk = k;     int ret = 0;     int qui = -1, q = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  S ) {         ++k;         --ns;       } else if (s[i] ==  H ) {         --nh;         if (k > 0)           --k;         else if (qui == -1) {           qui = i;           q = 1;         } else           ++q;       }       if (nh == 0 and k >= q) {         if (qui == -1 and ret < t) return true;         if (ret + (i - qui) < t) return true;         break;       }       ++ret;     }     k = zk;     int ult = -1;     int r = 0;     int ans = 0;     for (int i = 0; i < int(n); ++i) {       if (s[i] ==  S ) ++k;       if (k >= r and ult != -1) {         ans += i - ult;         if (v[i] > 0) ans += i - ult;         k -= r;         ult = -1;         r = 0;       }       if (s[i] ==  H ) {         if (k > 0)           --k;         else if (ult == -1) {           ult = i;           r = 1;         } else           ++r;       }       if (ult == -1 and v[i + 1] == 0) break;       ++ans;     }     return (ult == -1 and ans < t);   }   int main() {     cin >> n >> t;     cin >> s;     int lo = 0, hi = n, m;     while (hi - lo > 5) {       int m = (lo + hi) / 2;       if (puc(m, t))         hi = m;       else         lo = m;     }     bool trobat = 0;     if (puc(0, t)) {       cout << 0 << endl;       trobat = true;     }     for (int k = lo; !trobat and k <= hi; ++k) {       if (puc(k, t)) {         cout << k << endl;         trobat = true;       }     }     if (!trobat) cout << -1 << endl;   }   