import qualified Data.List as L

main :: IO ()
main = do
    _  <- getLine
    xs <- fmap read . words <$> getLine
    answer $ solve xs

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: [Int] -> Answer
solve = subtract 1 . L.head . go
  where
    go = inner . L.sortBy (flip compare)
    inner []           = undefined
    inner [x]          = [x]
    inner (1 : 1 : xs) = go $                   xs
    inner (1 : y : xs) = go $          pred y : xs
    inner (x : 1 : xs) = go $ pred x          : xs
    inner (x : y : xs) = go $ pred x : pred y : xs
