#include <bits/stdc++.h>
using namespace std;
long long t, k, n, a[500005], ch;
string s;
int pwr(int x) {
  int cnt = 0;
  if (x - 1 >= 0 and s[x - 1] == 'L') cnt++;
  return cnt;
}
int main() {
  cout << "1";
  while (t--) {
    cin >> n >> k >> s;
    queue<int> Q;
    unordered_set<int> dead;
    vector<pair<int, pair<int, int>>> pr;
    ch = 0;
    int pv = -1, nL = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        if (pv < 0) {
          pv = i;
        } else {
          pr.push_back(make_pair(i - pv, make_pair(pv, i)));
          pv = i;
        }
      } else
        nL++;
    }
    sort(pr.begin(), pr.end());
    for (int i = 0; i < pr.size(); i++) {
      int cl = pr[i].first, L = pr[i].second.first, R = pr[i].second.second;
      if (pwr(L) >= pwr(R)) {
        for (int j = L + 1; j < R and ch < k; j++) {
          if (s[j] == 'L') ch++, s[j] = 'W';
        }
      } else {
        for (int j = R - 1; j > L and ch < k; j--) {
          if (s[j] == 'L') ch++, s[j] = 'W';
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (s[i] == 'L' and ch < k) ch++, s[i] = 'W';
    }
    int ans = 0;
    pv = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W' and pv == 0) ans += 1;
      if (s[i] == 'W' and pv > 0) ans += 2;
      if (s[i] == 'L')
        pv = 0;
      else
        pv++;
    }
    cout << ans << "\n";
  }
  return 0;
}
