rt
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
ll f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(ll x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x/10);
putchar('0'+x%10);
}
inline void writeln(ll x) {
write(x);
putchar('\n');
}
namespace dsu {
ll f[2005];
ll find(ll n) {
if (f[n] == n) return f[n];
else return f[n] = find(f[n]);
}
void unite(ll a, ll b) {
f[find(a)] = find(b);
}
void init(ll size = 2000) {
for (int i = 1; i <= size; i ++) f[i] = i;
}
};
bool vis[2005];
ll n, m, p, q, ans;
char opt;
int main() {
n = read();
m = read();
dsu::init(2*n);
while (m --) {
opt = getchar();
p = read(), q = read();
if (opt == 'F') {
dsu::unite(p, q);
} else {
dsu::unite(q+n, p);
dsu::unite(p+n, q);
}
}
for (int i = 1; i <= n; i ++) {
if (dsu::f[i] == i) ans ++;
}
write(ans);
return 0;
}