fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val s = readLine() ?: return
    var c = s[0]
    var happy = 0
    var unhappy = 0
    1.until(s.length).forEach { i ->
        val ss = s[i]
        if (ss == c) {
            happy++
        } else {
            unhappy++
        }
        c = ss
    }
    val h = unhappy - k * 2
    if (h <= 0) {
        println((n - 1).toString())
    } else {
        println((n - 1 - h).toString())
    }
}