import Control.Monad
import qualified Data.Vector as V

main :: IO ()
main = do
    n <- readLn
    as <- replicateM n $ do
        a <- readLn
        return a
    print $ solve n $ V.fromList as

solve :: Int -> V.Vector Int -> Int
solve n as = f n 1
    where
        f 0 _ = -1
        f m i | i == 2 = n - m
              | otherwise = f (m-1) $ as V.! (i-1)

