import Control.Monad
import Data.Array

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- replicateM n readLn :: IO [Int]
  let as' = listArray (0, n) $ map (\l -> l - 1) as
  print $ solve n as'

solve :: Int -> Array Int Int -> Int
solve n as = go 0 0
  where
    go m c
      | c == 1 = m
      | m > n = -1
      | otherwise =
          let next = as ! c in
            go (m+1) next
