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 an = map read an0
    print $ solve 1 0 n an

solve :: Int -> Int -> Int -> [Int] -> Int
solve 2 x n an = x
solve i x n an = if x > n + 1
                         then -1
                         else solve (an !! (i-1)) (x+1) n an