import Data.Vector.Unboxed ((!),unfoldr,elemIndex,iterateN)
import qualified Data.ByteString.Lazy.Char8 as C
import Data.Maybe

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = fromMaybe (-1) . elemIndex 2 $ iterateN (v!0) (v!) 1