import scala.io.StdIn
object Main extends App {
  def encodeDirect[X](l: List[X]): List[(Int, X)] = {
    def _encodeDirect(res: List[(Int, X)], rem: List[X]): List[(Int, X)] = rem match {
      case Nil => res
      case ls => {
        val (s, r) = rem span { _ == rem.head }
        _encodeDirect(res:::List((s.length, s.head)), r)
      }
    }
    _encodeDirect(List(), l)
  }
  val List(n,k) = StdIn.readLine().split(" ").map(_.toInt).toList
  val S = StdIn.readLine()
  println((n-1).min(encodeDirect(S.toList).foldLeft(0)((z, n) => z + 0.max(n._1-1)) + 2 * k))
}
