import Data.List

main = do
  line1 <- getLine
  line2 <- getLine
  let
    [n,m] = map read $ words line1 :: [Int]
    ls = map read $ words line2 :: [Int]
    getDiffs ls = case ls of
      []         -> []
      x : []     -> [(x,x,0)]
      x : y : [] -> [(x,y,y-x)]
      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,_,_) : [] -> y-x
      (_,x,_) : (y,_,_) : tl -> y-x + (calcLength tl)
    in
      putStrLn $ show $ calcLength $ takeThrs (n-1) $ getDiffs $ sort ls


