include[HTML_REMOVED]
using namespace std;
const int N=40010;
int fa[N];
int n,m;
int find(int x){
if(x==fa[x]){
return x;
}
else return x=find(fa[x]);
}
int get(int x,int y){
return x*n+y;
}
signed main(){
cin>>n>>m;
for(int i=0;i[HTML_REMOVED]>x>>y>>op;
x–,y–;
int a=get(x,y);
int b=0;
if(op==’D’){
b=get(x+1,y);
}
else b=get(x,y+1);
int pa=find(a),pb=find(b);
if(pa==pb){
res=i;
break;
}
fa[pa]=pb;
}
if(res==0) cout<<”draw”<<endl;
else cout<<res<<endl;
return 0;
}