import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Set as Set
import Data.List
import Control.Monad

readInput :: IO [Int]
readInput = map (either error fst . T.decimal) . T.words <$> T.getLine

main = do
  [len, num] <- readInput
  locations <- readInput
  let distances = zipWith (-) (tail locations) locations
  print $ min (foldl' (+) 0 $ take (num - 1) $ len - last locations : distances)
    (sum distances)