import Data.List as L
import Data.Vector as V

difflist ::  [Int] -> [Int]
difflist [] = []
difflist [x] = []
difflist (x:y:ls) = (y-x) : (difflist (y:ls))

sortsnd = (V.reverse).(V.fromList).(sortOn snd) :: [(Int,Int)] -> Vector (Int,Int)

difflistsum :: Vector Int -> Vector Int -> Int
difflistsum ns list | ns == empty = (V.last list) - (V.head list)
                    | otherwise   = (V.last $ V.take n list) - (V.head $ V.take n list) + difflistsum (V.map (+(-n)) (V.tail ns)) (V.drop n list)
                      where n = V.head ns

main :: IO ()
main = do
  [n,m] <- L.map read.words <$> getLine :: IO [Int]
  xs <- (L.sort) . (L.map read.words) <$> getLine :: IO [Int]
  let ns = (V.fromList).(L.sort).(V.toList).(V.take (n-1)).fst.(V.unzip).sortsnd $ L.zip [1..(m-1)] (difflist xs) :: Vector Int
  if n >= m then print 0
  putStrLn $ show $ difflistsum ns (V.fromList xs)