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

main = do
    n  <- readLn
    as <- V.map pred . V.fromList <$> replicateM n readLn
    print $ solve as 0 0 n

solve as 1 i _ = i
solve as k i n
    | i==n = -1
    | otherwise = solve as (as V.! k) (succ i) n