import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List
import Data.Maybe


main = do
    [n, m] <- map read . words <$> getLine
    xs <- sort . map read . words <$> getLine
    let inter = sort . zipWith subtract xs $ tail xs
    print $ sum $ take (max 0 $ m - n) inter