diff (a:b:as) = (b - a):diff (b:as)
diff _ = []

main = do
    [k, n] <- map read . words <$> getLine :: IO [Int]
    a <- map read . words <$> getLine :: IO [Int]
    print $ k - max (k - last a + head a) (maximum (diff a))
