fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val s = readLine()!!
        .split("")
        .let { it.slice(1 until it.size - 1) }
        .map { if (it == "L") -1 else 1 }

    val result = s.countHappy() + 2 * k
    
    println(if(s.lastIndex < result) s.lastIndex else result)
}

fun List<Int>.countHappy(): Int {
    return this.withIndex().fold(0) { count, elm ->
        val indexFront = elm.index + elm.value
        if (0 <= indexFront && indexFront < this.size && this[indexFront] == elm.value) count + 1 else count
    }
}