import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do
    n <- readLn :: IO Int
    an0 <- replicateM n getLine
    let anx = map read an0
    let a = array (1,n) [(k,anx !! (k-1)) | k <- [1..n] ]
    print $ solve 1 0 n a

solve :: Int -> Int -> Int -> (Array Int Int) -> Int
solve 2 x n a = x
solve i x n a = if x > n + 1
                         then -1
                         else solve (a ! i) (x+1) n a