main = do
  n <- readLn :: IO Int
  bs <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ let k = breakBricks bs in if k == length bs then -1 else k

foldlState :: (c -> a -> b -> (c, a)) -> c -> a -> [b] -> a
foldlState f s a l = snd $ foldl (\(s,a) -> f s a) (s, a) l

breakBricks bs = foldlState step 1 0 bs
    where step k n b = if k == b then (k+1, n) else (k, n+1)
