import Data.List rInteger :: String -> Integer rInteger = read solve :: Int -> Int -> [Integer] -> Integer solve 1 _ as = 0 solve n k as = foldr (+) 0 ts where ts = take (n - k) $ sort xs xs = zipWith (-) (reverse (tail as)) (reverse (init as)) main = do [n, k] <- map read . words <$> getLine as <- sort . map rInteger . words <$> getLine print $ solve n k as