import Data.List

func [x] = []
func (x:y:ys) = (y-x):(func (y:ys))    

main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    x <- map read . words <$> getLine :: IO [Int]
    let s = (maximum x) - (minimum x)
    print $  s - (sum $ drop (m-n) (sort $ func $ sort x))