import qualified Data.IntMap as M

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- map read . words <$> getLine :: IO [Int]
  let m = makeMap $
          filter (\a -> a >= 0 && a <= 100000) $
          concatMap (\a -> [a-1, a, a+1]) ns
--  print m
  print $ solve m

makeMap :: [Int] -> M.IntMap Int
makeMap = foldr (\a b ->
                 case M.lookup a b of
                   Nothing -> M.insert a 1 b
                   Just k -> M.insert a (k+1) b) M.empty

solve :: M.IntMap Int -> Int
solve m = snd $
          M.foldWithKey (\k a (k', b) ->
                            if b < a
                            then (k, a)
                            else (k', b)) (-1, -1) m
