import Data.List

solve :: Int -> Int -> [Int] -> Int
solve a b c
 | notElem (b - a) c = b - a
 | notElem (b + a) c = b + a
 | otherwise = solve (a + 1) b c

main = do
 [x,n] <- map read . words <$> getLine :: IO [Int]
 print =<< if (n/=0) then (solve 0 x) . map read . words <$> getLine else return x