import Control.Applicative ((<$>)) minNumOfOps :: Integral a => a -> [a] -> a minNumOfOps = foldr (\x t -> if x == t then t - 1 else t) main :: IO () main = do n <- readLn :: IO Int xs <- fmap read . words <$> getLine :: IO [Int] print $ minNumOfOps n xs