import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

solve _  1 c = c
solve as n c
    | c > n = -1
    | otherwise = solve as (as !! n) (c + 1)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- replicateM n $ do
        a <- fst . fromJust . B.readInt <$> B.getLine
        return (a - 1)
    print $ solve as 0 0
