import Data.List
import Data.Ord

main = do 
    [n,m] <- map read . words <$> getLine :: IO [Int]
    xs <- sort . map read . words <$> getLine :: IO [Int]
    let xs' = sortBy (comparing Down) $ map snd $ scanl' (\(a, _) x -> (x, abs $ a - x)) (head xs, 0) (tail xs)
    print $ sum xs' - (sum $ take (n-1) xs')