import Data.List

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  xs <- map read . words <$> getLine
  print $ solve n xs

solve :: Int -> [Int] -> Int
solve n = sum . drop (n-1) . reverse . sort . distances . sort

distances :: [Int] -> [Int]
distances xs = zipWith subtract xs (tail xs)
