import Data.List (sort)
import Data.Bool (bool)

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  xs <- sort . map read . words <$> getLine
  print $ bool 0 gaps (n < m)
  where
    ds = map abs $ sort $ zipWith subtract xs (0 : xs)
    gaps = sum $ take (n - 1) ds
