main = do
  li <- getLine
  let [k,n] = map read $ words li
  li <- getLine
  let as = map read $ words li
  let ans = compute k as
  print ans

compute :: Int -> [Int] -> Int
compute k as = k - maximum ds
  where
    ds = zipWith (-) (tail as ++ [k+head as]) as
