import Control.Monad

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

solve :: 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
  
