import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc2(char c, int k, string s) {
    int n = cast(int)s.length;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'L') {
            if (i > 0 && s[i-1] == 'L') ans++;
        }
        else if (s[i] == 'R') {
            if (i + 1 < n && s[i + 1] == 'R') ans++;
        }
    }

    int[] ss;
    int[] t;
    for (int i = 0; i < n; i++) {
        if (s[i] == c) {
            if (i == 0) {
                t ~= 0;
            }

            if (i == n - 1) {
                t ~= 0;
            }

            if (i > 0 && s[i - 1] != c) t ~= 1;
            if (i + 1 < n && s[i + 1] != c) t ~= 1;

            if (t.length == 2) {
                ss ~= t.sum;
                t = [];
            }
        }
    }

    ss.sort();
    ss.reverse();
    return ss.take(k).sum + ans;
}

int calc(int k, string s) {
    int n = cast(int)s.length;
    return max(calc2('L', k, s.dup), calc2('R', k, s.dup));
}

void main() {
    int n, k; scan(n, k);
    string s = read!string;
    writeln(calc(k, s));
}
