import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  ds <- getLine :: IO String
  let
    s = VU.length . VU.filter id . (VU.zipWith (==) <$> id <*> VU.tail) . VU.fromList $ ds :: Int
  print $ (s + 2 * k) `min` (n - 1)
