#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,fa[N];

int getfa(int x) {
	return x==fa[x] ? x : fa[x]=getfa(fa[x]);
}

int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=m;i++) {
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		int fx=getfa(x),fy=getfa(y);
		if (fx!=fy) fa[fy]=fa[fx];
	}
	int ans=0;
	for (int i=1;i<=n;i++) 
		if (fa[i]==i) ans++;
	cout<<ans<<endl;	
	return 0;
}