import           Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = solve <$> readParams >>= print

readParams :: IO [Int]
readParams = map readInt . B.words <$> B.getContents

readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt

solve :: [Int] -> Int
solve (n:as) = maybe (-1) (n -) $ count as

count :: [Int] -> Maybe Int
count = go 0
  where
    go acc []
      | acc == 0   = Nothing
      | otherwise  = Just acc
    go acc (x:xs)
      | acc+1 == x = go (acc+1) xs
      | otherwise  = go acc xs
