import qualified Data.Vector.Unboxed as U

main = do
    n <- readLn
    as <- U.replicateM n readLn
    print $ solve 0 as 1

solve ac as i = let x = as U.! (i-1) in case x of
    1 -> -1
    2 -> ac+1
    _ -> solve (ac+1) as x