import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, m] <- getIntList
    xs <- sort <$> getIntList
    let xl = (last xs) - (head xs)
        ds = sortOn Down $ zipWith (-) (tail xs) xs
    print $ xl - sum (take (n-1) ds)