function Main(input) {
    var N = parseInt(input[0], 10);
    var K = parseInt(input[1], 10);
    var S = input.slice(2)[0].split('');

    var happy = 0;
    for (var i = 0; i < N; i++) {
        if (i === 0) {
            happy += S[i] === 'R' && S[i+1] === 'R';
        } else if (i === N - 1) {
            happy += S[i] === 'L' && S[i-1] === 'L';
        } else {
            if (S[i] === 'R') {
                happy += S[i+1] === 'R';
            } else {
                happy += S[i-1] === 'L';
            }
        }
    }

    console.log(happy);

    console.log(S);
    var convert = [S[0]];
    var direction = S[0];
    var index = 1;
    while (index < N) {
        if (S[index] !== direction) {
            direction = S[index];
            convert.push(S[index]);
        };
        index++;
    }
    console.log(convert);

    var edge = convert.length < 2 ? convert.length : 2;
    var middle = convert.length - edge;

    if (convert.length === 1) {
        // 一人の時は0
        return console.log(happy);
    }

    if (convert.length <= K) {
        happy += middle * 2 + edge * 1;
    } else {
        if (middle > K) {
            happy += K * 2;
        } else {
            happy += middle * 2 + (K - middle) * 1;
        }
    }
    console.log(happy > N - 1 ? N - 1 : happy);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));