import Control.Monad
import Data.Array
main=do
 n<-readLn
 a<-replicateM n readLn
 print(f 1 n 1 (array(1,n)(zip[1..n]a)))
  where f i n s a |i>n    = -1
                  |a!s==2 = i
                  |otherwise = f (i+1) n (a!s) a