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