
fun main() {
    abc140d()
}

fun abc140d() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val num = mutableListOf<Int>()
    var count = 0
    var p = ' '
    for (e in readLine()!!) {
        if (p != e) {
            p = e
            if (count > 0) num.add(count)
            count = 1
        } else {
            count++
        }
    }
    num.add(count)
    var precious = n - num.size
    if (num.size > k * 2) {
        precious += k * 2
    } else {
        precious = n - 1
    }
    println(precious)
}