import           Data.List
import           Data.Maybe
import qualified Data.ByteString.Char8         as C8

getInts :: IO [Int]
getInts = fmap (map (fst . fromJust . C8.readInt) . C8.words) C8.getLine

main :: IO ()
main = do
    [n, m] <- getInts
    xs     <- getInts
    print $ solve (m - n) (sort xs)

solve :: Int -> [Int] -> Int
solve k xs = sum . take k . sort . zipWith (-) (tail xs) $ xs
