#include <iostream>
using namespace std;
struct
DisjointSet
{
int
father[1001], ncnt;
DisjointSet( const int x )
{
memset( father, 0, sizeof father );
for( int i = 1; i <= x; i++ )
father[i] = i;
ncnt = x;
}
DisjointSet()
{
memset( father, 0, sizeof father );
for( int i = 1; i <= 1000; i++ )
father[i] = i;
ncnt = 1000;
}
int
getFather( int x )
{
if( father[x] == x )
return father[x];
else
{
int fx = getFather( father[x] );
father[x] = fx;
return father[x];
}
}
void
merge( const int x, const int y )
{
if( getFather( x ) != getFather( y ) )
father[getFather( x )] = getFather( y );
}
bool
judge( const int x, const int y )
{
if( getFather( x ) == getFather( y ) )
return true;
else
return false;
}
int
count()
{
int
a[1001] = { 0 }, cnt = 0;
for( int i = 1; i <= ncnt; i++ )
if( father[i] == i )
a[i]++;
for( int i = 1; i <= ncnt; i++ )
if( a[i] )
cnt++;
return cnt;
}
};
int
main()
{
int n, enemy[1001] = { 0 }, m;
cin >> n >> m;
DisjointSet friends( n );
for( int i = 1; i <= m ; i++ )
{
char f;
int
x, y;
cin >> f >> x >> y;
if( f == 'F' )
friends.merge( x, y );
if( f == 'E' )
{
if( enemy[x] == 0 )
enemy[x] = y;
else
friends.merge( enemy[x], y );
if( enemy[y] == 0 )
enemy[y] = x;
else
friends.merge( enemy[y], x );
}
}
cout << friends.count() << endl;
return 0;
}