solveN :: Int -> [Int] -> Int
solveN x ps
    | not $ x `elem` ps = x
    | otherwise = solveN (x - 1) ps

solveG :: Int -> [Int] -> Int
solveG x ps
    | not $ x `elem` ps = x
    | otherwise = solveG (x + 1) ps

solve :: Int -> [Int] -> Int
solve x ps =
    if x - n <= g - x then n else g
        where n = solveN x ps
              g = solveG x ps

main :: IO ()
main = do
    (x:_) <- map read . words <$> getLine :: IO [Int]
    ps <- map read . words <$> getLine :: IO [Int]
    print $ solve x ps