object Main {

  def main(args: Array[String]): Unit = {
    val Array(n,k) = readLine().split(" ").map(_.toInt)
    val S = readLine().toArray

    val start = S.foldLeft( ('a',List[Int]()))( (t, n) => {
      val list = t._2
      if(n == t._1) (n, (list.head + 1) :: list.tail)
      else (n, 1 :: list)
    })._2.map(_ - 1).sum

    println( (start + 2 * k) min (n -1))



  }
}