
import           Data.List
import Control.Applicative

cost :: Int -> [Int] -> Int
cost k ts = f (length ts) k (filter (>0) $ intervals ts)
  where
    intervals []         = []
    intervals [t]        = []
    intervals (t1:t2:ts) = t2 - (t1 + 1) : intervals (t2:ts)
    f n k itvls | k >= (length itvls + 1) = n
                | otherwise = n + sum (take (length itvls + 1 - k) (sort itvls))

main = do
  [n, k] <- fmap read . words <$> getLine
  ts <- fmap read . lines <$> getContents
  print $ cost k ts

