fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map { it.toInt() }
    val S = readInputLine().toCharArray()

    val dims = mutableListOf<Pair<Int, Int>>()
    
    var now = S[0]
    var start = 0
    
    for (i in 1 until N) {
        if (S[i] != now) {
            dims.add(Pair(start, i - 1))
            now = S[i]
            start = i
        }
    }

    dims.add(Pair(start, N - 1))

    println(Math.min(N - 1, dims.sumBy { it.second - it.first } + K * 2))
}

fun readInputLine(): String {
    return readLine()!!
}
