import Control.Monad
import Data.Array
import Data.Maybe
import qualified Data.ByteString.Char8 as BC


main :: IO ()
main = do
    n <- fst . fromJust . BC.readInt <$> BC.getLine
    as <- listArray (1, n) <$>
        replicateM n (fst . fromJust . BC.readInt <$> BC.getLine)
    putStrLn $ case lookup 2 (f n as 1 1) of
                Nothing -> "-1"
                Just i -> show i
    where
        f :: Int -> Array Int Int -> Int -> Int -> [(Int, Int)]
        f n as c i | c > n = []
        f n as c i = let i' = as ! i
                     in  (i', c) : f n as (c + 1) i'
