import Control.Monad
import Data.List

main = do
    [n, m] <- fmap read <$> words <$> getLine
    x      <- fmap read <$> words <$> getLine
    putStrLn $ show $ solve n m x

solve :: Int -> Int -> [Int] -> Int
solve n m x = sum $ take (m - n) dx
  where
    dx = sort $ map (\(a, b) -> b - a) $ zip sx $ drop 1 sx
    sx = sort x