import qualified Data.Vector.Unboxed.Mutable as UM

main = do
    n <- readLn
    as <- UM.replicateM n readLn
    solve 0 as 1 >>= print

solve ac as i = do
    x <- UM.read as (i-1)
    UM.write as (i-1) (-1)
    case x of
        -1 -> return (-1)
        2 -> return (ac+1)
        _ -> solve (ac+1) as x