#include <bits/stdc++.h>
#define int long long
using namespace std;

int count(const vector<string>& vs, const int K) {
    int n = vs.size();
    string s;
    char top = vs[0][0];
    for (int i = 0, k = 0; i < n; i++) {
        if (i % 2 && k >= K) s += vs[i];
        else s += string(vs[i].size(), top);
        k += i % 2;
    }

    int ret = s.size();
    s = "R" + s + "L";
    for (int i = 1; i < s.size(); i++) {
        char t = s[i + (s[i] == 'L' ? -1 : 1)];
        ret -= (t != s[i]);
    }
    cerr << s << " " << ret << endl;
    return ret;
}

signed main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    vector<string> vs;
    char last = '"';
    for (char c : S) {
        if (last != c) vs.push_back(string(1,c));
        else vs.back() += c;
        last = c;
    }

    int ans = count(vs, K);
    reverse(vs.begin(), vs.end());
    ans = max(ans, count(vs, K));
    cout << ans << endl;
}
