main = do
    n <- readLn :: IO Int
    hs <- map read . words <$> getLine :: IO [Int]
    print $ solve 0 hs

solve :: Int -> [Int] -> Int
solve n hs = case 0 `elem` hs of
    True -> foldl solve n $ split 0 hs
    False -> 1 + solve n (map (\x -> x-1) hs)

split  :: Eq a => a -> [a] -> [[a]]
split p xs =  case dropWhile (\x -> x==p) xs of
                      [] -> []
                      xs' -> w : split p xs''
                            where (w, xs'') = break (\x -> x==p) xs'