import Data.List
 
difflist :: [Int] -> [Int]
difflist [] = []
difflist [x] = []
difflist (x:y:ls) = (y-x) : (difflist (y:ls))
 
sortsnd = reverse.sortOn snd
 
difflistsum :: [Int] -> [Int] -> Int
difflistsum [] list = (last list) - (head list)
difflistsum (n:ns) list = (last $ take n list) - (head $ take n list) + difflistsum (map (+(-n)) ns) (drop n list)
 
main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  xs <- sort . (map read.words) <$> getLine
  let ns = sort.(take (n-1)).fst.unzip.sortsnd $ zip [1..(m-1)] (difflist xs)
  if n >= m then print 0
    else putStrLn $ show $ difflistsum ns xs