#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 幸福な人数をカウントする
int count_happy(int N, vector<char> line){
    int count = 0;
    for (int i = 0; i < N; i++){
        if (i == 0 && line[0] == 'L') continue;
        if (i == N-1 && line[N-1] == 'R') continue;
        if (line[i] == 'L' && line[i-1] == 'L') count++;
        else if (line[i] == 'R' && line[i+1] == 'R') count++;
    }
    return count;
}

// l番目からr番目までを回転 (0index)
// 参照渡し(無駄なコピーを行わないため)
vector<char> rot_line(int l, int r, vector<char>& line){
    for (int i = 0; i <= r-l; i++){
        if (line[l+i] == 'L') line[l+i] = 'R';
        else if (line[l+i] == 'R') line[l+i] = 'L';
    }
    for (int i = 0; i <= (r-l+1)/2; i++){
        swap(line[l+i], line[r-i]);
    }
    return line;
}

int main()
{
    int N, K, rot1, rot2;
    cin >> N >> K;
    vector<char> S(N);
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }

    int count_k = 0;

    // RL LR を検出して、L-L間を入れ替え
    for (int i = 0; i < N-1; i++){
        if (S[i] == 'R' && S[i+1] == 'L'){
            for (int j = i+1; j < N-1; j++){
                if (S[j] == 'L' && S[j+1] == 'R'){
                    rot1 = i+1;
                    rot2 = j;
                    S = rot_line(rot1, rot2, S);

                    // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                    // for (int i = 0; i < N; i++){
                    //     cout << S[i];
                    // }
                    // cout << endl;

                    count_k++;
                    break;
                }
            }
        }
        if (count_k == K) break;
    }

    if (count_k < K){
        // LR RL を検出して、R-R間を入れ替え
        for (int i = 0; i < N-1; i++){
            if (S[i] == 'L' && S[i+1] == 'R'){
                for (int j = i+1; j < N-1; j++){
                    if (S[j] == 'R' && S[j+1] == 'L'){
                        rot1 = i+1;
                        rot2 = j;
                        S = rot_line(rot1, rot2, S);

                        // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                        // for (int i = 0; i < N; i++){
                        //     cout << S[i];
                        // }
                        // cout << endl;

                        count_k++;
                        break;
                    }
                }
            }
            if (count_k == K) break;
        }
    }

    // 回転がK回に達していない時、ここまでで、４パターンになっている
    // 全てL、全てR、前半L後半R、前半R後半L
    // 前後半が違うパターンは1度だけ回転が必要

    if (count_k < K){
        if (S[0] != S[N-1]){
            for (int i = 0; i < N-1; i++){
                if (S[i] != S[i+1]){
                    rot1 = 0;
                    rot2 = i;
                    S = rot_line(rot1, rot2, S);

                    // cout << "l: " << rot1 << ", r: " << rot2 << ", line: ";
                    // for (int i = 0; i < N; i++){
                    //     cout << S[i];
                    // }
                    // cout << endl;

                    count_k++;
                    break;
                }
            }
        }
    }

    cout << count_happy(N, S) << endl;

    return 0;
}


Measured memory_bytes: 384