#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define fill(a,v) memset(a,v,sizeof(a))
#define bitcount __buitin_popcount
#define gcd __gcd
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vi > vvi;
map<pii,pii> dad;
map<pii,ll> rnk;
void UNION(pii x,pii y)
{
if(rnk[x] > rnk[y])
dad[y] = x;
else
{
dad[x] = y;
if(rnk[y] == rnk[x])
rnk[x]++;
}
}
pii FIND(pii x)
{
if(dad[x] != x)
{
dad[x] = FIND(dad[x]);
}
else return x;
}
int main()
{
ll n;
while(cin >> n)
{
if(n == -1) return 0;
int m;cin >> m;
pii query[m];
string parity[m];
for(int i = 0 ; i < m ; ++i)
{
cin >> query[i].fi >> query[i].se;
cin >> parity[i];
}
int cnt = 0;
for(int i = 0 ; i < m ; ++i)
{
int x = query[i].fi,y = query[i].se;
pii s= mp(x-1,0),s1 = mp(x-1,1),d = mp(y,0),d1 = mp(y,1);
dad[s] = s;
rnk[s] = 0;
dad[s1] = s1;
rnk[s1] = 0;
dad[d] = d;rnk[d] = 0;
dad[d1] = d1;rnk[d1] = 0;
}
for(int i = 0 ; i < m ; ++i)
{
int x = query[i].fi,y = query[i].se;
pii s= mp(x-1,0),s1 = mp(x-1,1),d = mp(y,0),d1 = mp(y,1);
if(parity[i] == "even")
{
UNION(FIND(s),FIND(d));
UNION(FIND(s1),FIND(d1));
}
else
{
UNION(FIND(s1),FIND(d));
UNION(FIND(s),FIND(d1));
}
if(FIND(s) == FIND(s1)) goto p;
else if(FIND(d) == FIND(d1) ) goto p;
cnt++;
}
p: cout << cnt << endl;
}
return 0;
}
I2luY2x1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ICAgZWxzZQogICAgewogICAgICAgIGRhZFt4XSA9IHk7CiAgICAgICAgaWYocm5rW3ldID09IHJua1t4XSkKICAgICAgICAgICAgcm5rW3hdKys7CiAgICB9Cn0KcGlpIEZJTkQocGlpIHgpCnsKICAgIGlmKGRhZFt4XSAhPSB4KQogICAgewogICAgICAgIGRhZFt4XSA9IEZJTkQoZGFkW3hdKTsKICAgIH0KICAgIGVsc2UgcmV0dXJuIHg7Cn0KaW50IG1haW4oKQp7CiAgIAoKICAgIGxsIG47CiAgICB3aGlsZShjaW4gPj4gbikKICAgIHsKICAgICAgICBpZihuID09IC0xKSByZXR1cm4gMDsKCiAgICAgICAgaW50IG07Y2luID4+IG07CiAgICAgICAgcGlpIHF1ZXJ5W21dOwogICAgICAgIHN0cmluZyBwYXJpdHlbbV07CgogICAgICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgbSA7ICsraSkKICAgICAgICB7CiAgICAgICAgICAgIGNpbiA+PiBxdWVyeVtpXS5maSA+PiBxdWVyeVtpXS5zZTsKICAgICAgICAgICAgY2luID4+IHBhcml0eVtpXTsKICAgICAgICB9CgogICAgICAgICAgaW50IGNudCA9IDA7CiAgICAgICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgbSA7ICsraSkKICAgICAgICAgewogICAgICAgICAgICBpbnQgeCA9IHF1ZXJ5W2ldLmZpLHkgPSBxdWVyeVtpXS5zZTsKICAgICAgICAgICAgcGlpIHM9IG1wKHgtMSwwKSxzMSA9IG1wKHgtMSwxKSxkID0gbXAoeSwwKSxkMSA9IG1wKHksMSk7CiAgICAgICAgICAgIGRhZFtzXSA9IHM7CiAgICAgICAgICAgIHJua1tzXSA9IDA7CiAgICAgICAgICAgIGRhZFtzMV0gPSBzMTsKICAgICAgICAgICAgcm5rW3MxXSA9IDA7CiAgICAgICAgICAgIGRhZFtkXSA9IGQ7cm5rW2RdID0gMDsKICAgICAgICAgICAgZGFkW2QxXSA9IGQxO3Jua1tkMV0gPSAwOwogICAgICAgICB9CiAgICAgICAgZm9yKGludCBpID0gMCA7IGkgPCBtIDsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHggPSBxdWVyeVtpXS5maSx5ID0gcXVlcnlbaV0uc2U7CiAgICAgICAgICAgIHBpaSBzPSBtcCh4LTEsMCksczEgPSBtcCh4LTEsMSksZCA9IG1wKHksMCksZDEgPSBtcCh5LDEpOwoKICAgICAgICAgICAgaWYocGFyaXR5W2ldID09ICJldmVuIikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgVU5JT04oRklORChzKSxGSU5EKGQpKTsKICAgICAgICAgICAgICAgIFVOSU9OKEZJTkQoczEpLEZJTkQoZDEpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIFVOSU9OKEZJTkQoczEpLEZJTkQoZCkpOwogICAgICAgICAgICAgICAgVU5JT04oRklORChzKSxGSU5EKGQxKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAKICAgICAgICAgICAgIGlmKEZJTkQocykgPT0gRklORChzMSkpIGdvdG8gcDsKICAgICAgICAgICAgIGVsc2UgaWYoRklORChkKSA9PSBGSU5EKGQxKSApIGdvdG8gcDsKICAgICAgICAgICAgIGNudCsrOwogICAgICAgIH0KCiAgICAgICAgcDogY291dCA8PCBjbnQgPDwgZW5kbDsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=