import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readContents 2 >>= main'
    where
        main' [[n, m], xs] = print . solve n m $ sort xs

solve :: Int -> Int -> [Int] -> Int
solve n m xs
    | n >= m = 0
    | otherwise = last xs - head xs + 1 - n - r
    where
        r = sum $ take (n - 1) ds 
        ds = sortBy (flip compare) $ diffs xs
        diffs (x : y : zs) = (y - x - 1) : diffs (y : zs)
        diffs _ = []

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine