import           Control.Applicative
import           Control.Monad
import qualified Data.Vector                   as V

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

  print $ f n (V.fromList bs) 1 [0 ..]

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