gets;~/ /;a=eval$';r=gets[a-=1];c=0 p$$.times{|i|break x+1if(c+=r==$_[x=a+(81-r.ord*2)*i]?1:-1)<1}