#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
 
int sum(const int n, char* s)
{
    int sum = 0;
    for(int i=0; i<n; i++){
        if(s[i] == 'L'){
            if(i == 0){
            }else if(s[i] == s[i-1]){
                sum += 1;
            }
        }else{
            if(i == n-1){
            }else if(s[i] == s[i+1]){
                sum += 1;
            }  
        }
    }
    return sum;
}
 
void swap(const int n, char* s, int l, int r)
{
    char tmp;
    //cout << s << ":" << l << ":" << r << endl;
    for(int i=0; i<n; i++){
        if(l > r){
            break;
        }else if(l == r){
            s[l] = (s[l]=='L')? 'R':'L';
        }else{
            tmp = s[r];
            s[r] = (s[l]=='L')? 'R':'L';
            s[l] = (tmp=='L')? 'R':'L';
        }
        l++; r--;
    }
    //cout << s << endl;
    return;
}
 
int foo(const int n, const int k, char* s)
{
    int l = 0;
    int r = 0;
    int lastl = 0;
    int lastr = 0;
    int index = 1;
    int ans = sum(n, s);
    for(int i=0; i<k; i++){
        //cout << "-----" << endl;
        //cout << s << ":" << ans << endl;
        char tmp = s[0];
        for(int j=index; j<n; j++){
            if(tmp != s[j]){
                if(l == lastl){
                    l = j;
                    tmp = s[j];
                }else{
                    r = j-1;
                    break;
                }
            }
        }
        if(l == lastl){
            // 全てL(R)のパターン
            // 値を出力して終了
            break;
        }else if(r == lastr){
            // L/R境界が1点のパターン
            // 端までをスワップすると+1
            // 値を出力して終了
            r = n - 1;
            //swap(n, s, l, r);
            ans += 1;
            break;
        }else{
            // LRRLまたはRLLRが見つかった
            // LLLLまたはRRRRに変換して+2
            // 文字列を更新して次のループへ
            //swap(n, s, l, r);
            ans += 2;
            //cout << ans << endl;
            //if(ans != sum(n, s)){
            //    cout << "!! " << ans << " != " << sum(n,s) << endl;
            //}
        }
        index = r+1;
        lastl = l;
        lastr = r;
    }
    return ans;
}

int foo2(const int n, const int k, char* s)
{
    int ct=0;
    for(int i=0; i<n-1; i++){
        ct+= s[i]==s[i+1];
    }
    return min(ct+2*k,n-1);
}

#define rep(i, n) for(int i = 0; i < n; i++)
int bar(const int n, const int k, char* s)
{
    int ct=0;
    rep(i,n-1){
        ct+= s[i]==s[i+1];
    }
    return min(ct+2*k,n-1);
}

int main()
{
    int n,k;
    cin >> n >> k;
    //char s[n];
    //cin >> s;
    //cout << foo(n, k, s) << endl;
    string s;
    cin >> s;
    cout << foo(n, k, (char*)s.c_str()) << endl;
    // test2
    /*
    k = 1;
    n = 40;
    std::string ss(n, 'L');
    for(int i=0; i<n+1; i++){
        //cout << "-----" << endl << ss << endl;
        do {
            //std::cout << ss << std::endl;
            int ans2 = bar(n, k, (char*)ss.c_str());
            //int ans1 = foo2(n, k, (char*)ss.c_str());
            int ans1 = ans2;
            if(ans1 != ans2){
                cout << n << ", " << k << ", " << ss << endl;
                cout << ans1 << " != " << ans2 << endl; 
            }
            //cout << ans1 << " == " << ans2 << endl; 
        } while (std::next_permutation(ss.begin(), ss.end()));
        if(i == n) break;
        ss[n-1-i] = 'R';
    }
    cout << n << ":" << k << " All OK !!" << endl; 
    */
    return 0;
}

Measured memory_bytes: 512