import Control.Monad
import Control.Applicative
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Lazy.Char8 as BSL


main :: IO ()
main = do
  n <- read <$> getLine
  as <- VU.map (subtract 1)
      . VU.unfoldrN n (BSL.readInt . BSL.dropWhile (<'!')) <$> BSL.getContents
  print $ fromMaybe (-1)
        $ VU.elemIndex 1 $ VU.iterateN (n+1) (as VU.!) 0