import Data.List

main :: IO ()
main = do
  [n, m] <- readInts
  xs <- sort <$> readInts
  print $ solve n m xs

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve n m xs
  | n >= m = 0
  | otherwise = solve' n xs

solve' :: Int -> [Int] -> Int
solve' n xs = (xm - x1) - solve'' n ls
  where
    x1 = head xs
    xm = last xs
    ls = zipWith (-) (tail xs) xs

solve'' :: Int -> [Int] ->Int
solve'' n ls = sum $ take (n - 1) $ sortBy (flip compare) ls
