import Data.Functor
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  ls <- sort . unfoldr (BS.readInt . BS.dropWhile (<'!')) <$> BS.getLine
  let diffs = sort $ zipWith (-) (tail ls) ls
  print $ sum $ take (max 0 $ m-n) $ diffs