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

solve :: (Array Int 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)
    let arr = listArray (0,n-1) a
    print $ solve arr 0 1
