import Data.List (sortBy)

sort::[Int]->[Int]
sort = sortBy compare

main = do
  [n,m] <- map read . words <$> getLine::IO[Int]
  xn <- map read . words <$> getLine::IO[Int]
  let sortPoints = sort xn
  let diff = sort . map abs $ zipWith (-) sortPoints $ tail sortPoints
  print $ sum $ take (n+1) diff