import Debug.Trace
import qualified Data.Map as Map

scan :: [Int] -> Int -> Int
scan xs = iter 0 where
    iter s e
        | e - s == 1 = e
        | check m xs = iter s m
        | otherwise  = iter m e
        where m = div (s+e) 2
    check m = iter Map.empty 0 where
        iter ps _ [] = True
        iter ps pl (x:xs)
            | pl <  x   = iter ps x xs
--            | pl <  x   = trace ("tr0 m:" ++ show m ++  " nl:"++ show x ++ " ns:" ++ show ps ++ " xs:" ++ show xs) $ iter ps x xs
            | otherwise = case next (Map.filterWithKey (\k _ -> k < x) ps) x of
                Just ns -> iter ns x xs
--                Just ns -> trace ("tr1 m:" ++ show m ++ " nl:"++ show x ++ " ns:" ++ show ns ++ " xs:" ++ show xs) $ iter ns x xs
                Nothing -> False
            where
                next _ 0 = Nothing
                next ns x = case Map.lookup k ns of 
                        Just v  -> if p v   then Just (Map.update (\_ -> Just (v+1)) k ns)
                                            else next (Map.delete k ns) (x-1)
                        Nothing -> if p 0   then Just (Map.insert k 1 ns)
                                            else Nothing
                    where
                        k = x - 1
                        p v = m - 1 > v

readData :: IO [Int]
readData = do
    line1 <- getLine
    let xs = map (\x -> read x :: Int) (words line1)
    return xs

main :: IO() 
main = do
    n  <- readLn :: IO Int
    la <- readData
    let ans = scan (take n la) n
    print ans