import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  bs <- replicateM n readLn

  print $ f n bs 1 [0..]

f n bs o (i:is)
  | i > n = -1
  | bs !! (o - 1) == 2 = i + 1
  | otherwise = f n bs (bs !! (o - 1)) is