1 #include <iostream>
2 using namespace std;
3 struct node
4 { int x,y;}f[301][301],k1,k2;
5 int i,j,m,n,x,y;
6 char c;
7 node root(node k)
8 {
9 if((f[k.x][k.y].x==k.x)&&(f[k.x][k.y].y==k.y))return k;
10 f[k.x][k.y]=root(f[k.x][k.y]);
11 return f[k.x][k.y];
12 }
13 int main()
14 {
15 cin>>n>>m;
16 for(i=1;i<=n;i++)
17 for(j=1;j<=n;j++)
18 {f[i][j].x=i;f[i][j].y=j;}
19 for(i=1;i<=m;i++)
20 {
21 cin>>x>>y>>c;
22 if(c=='D') {k1=root(f[x][y]);k2=root(f[x+1][y]);}
23 if(c=='R') {k1=root(f[x][y]);k2=root(f[x][y+1]);}
24 if((k1.x==k2.x)&&(k1.y==k2.y)) {cout<<i<<endl;return 0;}
25 else f[k1.x][k1.y]=k2;
26 }
27 cout<<"draw"<<endl;
28 return 0;
29 }