fun main(args:Array<String>){
  val (n,k) = readLine()!!.split(" ").map{it.toInt()}
  val rl = readLine()!!
  var happy = 0
  for(i in 1 until n){
    if(rl[i]==rl[i-1])happy++
  }
  println(Math.min(n-1,happy+2*k))
}