import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    var nk = readWords { Int($0)! }.makeIterator()
    let n = nk.next()!
    let k = nk.next()!

    // 13 3
    // LRRLRLRRLRLLR
    // LRRLRLLLLRLLR
    // LRRLRRRRRRLLR
    // LRRLLLLLLLLLR

    let S = ["R"] + Array(readLine()!) + ["L"]
    var count = 0
    var rl = 0
    for i in 0..<n-1 {
        if S[i] == S[i+1] {
            count += 1
        } else if S[i] == "R" && S[i+1] == "L" {
            rl += 1
        }
    }

    let change = rl > k ? k : rl

    print(count + change * 2)
}

main()