fun main(args:Array<String>) {
    val line = readLine()!!.split(" ").map { it.toInt() }
    val n = line[0]
    val k = line[1]
    val l = readLine()!!
    var result = 0
    var b = 0
    var before = 'x'
    for(i in 0..n-1){
        if(before == l[i]){
            result++
        }else{
            b++
        }
        before = l[i]
    }
    if(b%2==1){
        val x = (b-1)/2
        result += 2 * if(x>k)k else x
    }else{
        val x = b/2
        if(x<=k){
            result+= 2*x - 1
        }else{
            result += 2*k
        }
    }
    println(result)
}