fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map { it.toInt() }
  val cList = readLine()!!.map { it }

  var inCnt = 0
  var outCnt = 0
  var happyCnt = 0
  for (i in 1 until n) {
    val l = cList[i - 1]
    val r = cList[i]
    if (l == 'L' && r == 'R') outCnt++
    if (l == 'R' && r == 'L') inCnt++
    if (l == 'L' && r == 'L') happyCnt++
    if (l == 'R' && r == 'R') happyCnt++
  }

  var swap2 = Math.min(inCnt, outCnt)
  var swap1 = Math.max(inCnt, outCnt) - swap2

  for (i in 0 until k) {
    if (swap2 > 0) {
      happyCnt += 2
      swap2--
    } else if (swap1 > 0) {
      happyCnt++
      swap1--
    }
  }

  println(happyCnt)
}

