import Data.List

main = do
  line1 <- getLine
  line2 <- getLine
  let
    [n,m] = map read $ words line1 :: [Int]
    ls = map read $ words line2 :: [Int]
    addFstDiff ls =
      case ls of
        []   -> getDiffs ls
        x:tl -> (x,x,100000) : getDiffs ls
    getDiffs ls = 
      case ls of
        []         -> []
        x : []     -> [(x,x,100000)]
        x : y : tl -> (x,y,y-x) : getDiffs (y:tl)
    takeThrs n ls = sortBy (\(x,_,_) -> \(y,_,_) -> compare x y)
                    $ take n
                    $ (sortBy (\(_,_,x) -> \(_,_,y) -> (flip compare) x y)) ls
    calcLength ls = case ls of
      []                     -> 0
      x : []                 -> 0
      (_,x,_) : (y,y2,y3) : tl -> y-x + (calcLength ((y,y2,y3):tl))
    in
      putStrLn $ show $ calcLength $ takeThrs (n+1) $ addFstDiff $ sort ls


