#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

const int N=1e5+10 ;

int f[N] , v[N] ;
inline int find ( int x ) { return f[x]==x?x:f[x]=find(f[x]); }

int n , m ;
int main ()
{
	int i , x , y , z , res=0 ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<=n ; i++ ) f[i]=i;
	for ( i=1 ; i<=m ; i++ ) scanf("%d%d%d",&x,&y,&z),f[find(x)]=find(y);
	for ( i=1 ; i<=n ; i++ ) 
		if ( !v[find(i)] ) res++,v[find(i)]=1;
	printf("%d\n",res);
	return 0 ;
}