#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m,fx,fy,xx,yy,zz,f[110000],ans;
int father(int x){
	if (f[x]!=x) f[x]=father(f[x]);
	return f[x];
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n) f[i]=i;ans=n;
	fo(i,1,m){
		scanf("%d%d%d",&xx,&yy,&zz);
		fx=father(xx);fy=father(yy);
		if (fx!=fy){
			f[fx]=fy;
			ans--;
		}
	}
	printf("%d\n",ans);
	return 0;
}