import Control.Monad
import Control.Applicative
import Data.List




getBysplit = map read . words <$> getLine

main :: IO()
main = do
  [n, m] <- getBysplit :: IO [Int]
  xlst <- getBysplit :: IO [Int]
  let (x:xs) = sort  xlst
  let difflist = diffList x xs
  let ans = (sum . take (m - n) . sort) difflist
  print ans

diffList :: Int -> [Int] -> [Int]
diffList pre [] = []
diffList pre (x:xs) = (x - pre):diffList x xs
