传送门
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
int f[maxn],emc[maxn];
int find(int x){
while(x != f[x])
x = f[x];
return x;
}
void hebing(int x, int y){
int a = find(x),b = find(y);
if(a == b)
return;
f[a] = b;
return;
}
int main(){
int n,m,q,p;
char c;
cin >> n>>m;
for(int i = 1;i <= n;++ i)
f[i] = i;
for(int i = 1;i <= m;++ i){
cin >> c;
cin >> q >> p;
if(c == 'F')
hebing(q,p);
else{
if(emc[q] == 0)
emc[q] = find(p);
else
hebing(q,emc[p]);
if(emc[p] == 0)
emc[p] = find(q);
else
hebing(p,emc[q]);
}
}
int count[maxn] = {0},cnt = 0;
for(int i = 1;i <= n;++ i)
count[find(i)] ++;
for(int i = 1;i <= n;++ i)
if(count[i])
cnt ++;
cout << cnt << endl;
return 0;
}