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


solve :: [Int] -> Int -> Int -> Int
solve arr idx count
    | count > length(arr) = -1
    | arr!!idx == 1 = count
    | otherwise = solve arr (arr!!idx) (count + 1)

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