import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

getInts::IO[Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main = do
  [k,n] <- map read . words <$> getLine
  an <- getInts
  let an' = an ++ [(k+(an !! 0))]
  print $ k - (maximum $ zipWith (-) (tail an') an')