#include <iostream>
using namespace std;
int f[40050];
int n, m;
void init()
{
for (int i = 1; i <= 40000; i++)
f[i] = i;
}
int findr(int x)
{
if (f[x] != x)
f[x] = findr(f[x]);
return f[x];
}
bool mset(int a, int b)
{
int fa = findr(a);
int fb = findr(b);
if (fa != fb)
{
f[fa] = fb;
return false;
}
else
return true;
}
int getnum(int x, int y)
{
return (x - 1) * n + y; // 二维变一维
}
int main()
{
init();
cin >> n >> m; // 3 5
for (int i = 1; i <= m; i++)
{
int x, y;
char c;
cin >> x >> y >> c;
int a = getnum(x, y);
int b = 0;
if (c == 'D')
b = getnum(x + 1, y);
else
b = getnum(x, y + 1);
if (mset(a, b))
{
cout << i;
return 0;
}
}
cout << "draw";
return 0;
}