fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.map { it.toChar() } as MutableList
    var count = 0

    for ((s1, s2) in s.subList(0, n-1).zip(s.subList(1, n))) {
        if (s1 == 'R' && s2 == 'L' && s[0] == 'L') {
            count += 1
        }

        if (s1 == 'L' && s2 == 'R' && s[0] == 'R') {
            count += 1
        }
    }

    if (s[0] == s[n-1]) {
        println(
                when {
                    (k >= count) -> n - 1
                    else -> n - 1 - (2 * (count - k))
                }
        )
    } else {
        println(
                when {
                    (k - 1 >= count) -> n - 1
                    else -> n - 2 - (2 * (count - k))
                }
        )
    }
}