fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}
    val S = readLine()!!
    val T = S.toCharArray().fold(StringBuilder()) { s, c -> if (s.isEmpty() || s.last() != c) s.append(c) else s }.toString()

    println(N - 1 - Math.max(0, T.length - 1 - 2 * K))
}
