module Main where


main :: IO ()
main = do
    [k, n] <- map read . words <$> getLine
    homeList <- map read . words <$> getLine

    let numList = getNum (homeList ++ [k+(head homeList)])
    let sumNum = foldl (\acc x-> acc + x ) 0 numList
    let maxNum = foldr (\acc x -> if x>acc then x else acc) 0 numList
    putStrLn (show (sumNum - maxNum))

getNum :: [Int]->[Int]
getNum [] = []
getNum (_:[]) = []
getNum (x:xs) = [(head xs)-x] ++ getNum xs

