#include <bits/stdc++.h>
using namespace std;
struct Condition { int u, v, t; } a[200001];
int f[400002], n, m;
int zuxian(int k) { return f[k] == k ? k : f[k] = zuxian(f[k]); }
int main() {
freopen("parity.in","r",stdin);
freopen("parity.out","w",stdout);
cin >> n >> m;
vector<int> b;
for (int i = 0; i < m; ++i) {
string s;
cin >> a[i].u >> a[i].v >> s;
a[i].u--;
a[i].t = (s[0] == 'o');
b.push_back(a[i].u);
b.push_back(a[i].v);
}
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
int l = b.size();
iota(f, f + 2 * l + 1, 0);
for (int i = 0; i < m; ++i) {
int u = lower_bound(b.begin(), b.end(), a[i].u) - b.begin() + 1;
int v = lower_bound(b.begin(), b.end(), a[i].v) - b.begin() + 1;
int t = a[i].t;
int cond = v + (1 - t) * l;
if (zuxian(u) == zuxian(cond)) {
cout << i;
return 0;
}
f[zuxian(u)] = zuxian(v + t * l);
f[zuxian(u + l)] = zuxian(v + (1 - t) * l);
}
cout << m;
}