import Data.List
import Data.Ord

solve :: Int -> [Int] -> Int
solve n xs = (last xs - head xs) - zs
  where diffList = zipWith (-) (tail xs) xs
        sortDesc = sortOn Down
        zs = sum $ take (n - 1) $ sortDesc diffList

main :: IO ()
main = do
  [n, _] <- map read . words <$> getLine :: IO [Int]
  xs <- sort . map read . words <$> getLine
  print $ solve n xs