#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<queue>
#define int long long
using namespace std;
const int N=5009;
int n,m,b[N],f[N],ans;
char c;
int mn(int i,int j){return i<j?i:j;}
int mx(int i,int j){return i<j?j:i;}
int jdz(int k){return k>0?k:-k;}
inline int read()
{
register int x=0,f=1;
char c=getchar();
while(c<'0' || c>'9') {if(c=='-')f=-1;c = getchar();}
while(c>='0' && c<='9') { x = x*10 + c -48; c = getchar(); }
return x*f;
}
int find(int x)
{
if(f[x]==x) return f[x];
return f[x]=find(f[x]);
}
signed main()
{
freopen("group.in","r",stdin);
freopen("group.out","w", stdout);
n=read();m=read();
for(int i=1;i<=n;i++)f[i]=i;
for(int t1,t2,i=1;i<=m;i++){
c=getchar();
t1=read();t2=read();
int x=find(t1),y=find(t2);
if(c=='F')
{
f[x]=y;
}
if(c=='E')
{
if(b[t1]) f[find(t2)]=find(b[t1]);
else b[t1]=find(t2);
if(b[t2]) f[find(t1)]=find(b[t2]);
else b[t2]=find(t1);
}
}
for(int i=1;i<=n;i++)if(f[i]==i)ans++;cout<<ans;
return 0;
}