import Data.Array.IArray
import Data.List

main = do
  n <- readLn :: IO Int
  a <- getContents >>= return . (map read) . lines :: IO [Int]

  let arr = listArray (1, n) a :: Array Int Int

  let
    func _ 0 = []
    func i n = i : (func (arr!i) (n-1))

  putStrLn $ g (elemIndex 2 (func 1 n))
  where
    g Nothing = "-1"
    g (Just x) = show x
