#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define x first
#define y second
typedef pair<long long, long long> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ull;
typedef long long ll;
const int N = 2e3 + 10;
int p[N], d[N];
int find(int x){
if(p[x] != x){
int r = find(p[x]);
d[x] ^= d[p[x]];
p[x] = r;
}
return p[x];
}
void solve()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++) p[i] = i;
while(m --){
string s;
cin >> s;
int a, b;
cin >> a >> b;
int t = 0;
if(s[0] == 'E'){
t = 1;
}
p[find(a)] = find(b);
d[find(a)] = d[a] ^ d[b] ^ t;
}
int cnt = 0;
cout << cnt << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while( t -- )
{
solve();
}
return 0;
}