import qualified Data.List as L

toInt x = read x :: Int

nearX :: Int -> ([Int], [Int]) -> Int
nearX x ([], ys) = head ys
nearX x (xs, []) = last xs
nearX x (xs, ys) = if alxs > alys  then lys
                                   else lxs
                where
                    lxs = last xs
                    lys = head ys
                    alxs = abs (x - lxs)
                    alys = abs (x - lys)

main = do
    xn <- map toInt . words <$> getLine
    pi <- map toInt . words <$> getLine
    let x = head xn
        pj = [0..100] L.\\ pi
        tupleP = span (<x) pj
    print $ nearX x tupleP