#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5+15;
int pre[maxn],n,m,x,y,z,vis[maxn];
int Find(int x){
	return pre[x] == x ? x : pre[x] = Find(pre[x]);
}
void mix(int x,int y){
	int fx = Find(x);
	int fy = Find(y);
	if(fx != fy) pre[fx] = fy;
}
int main(){
	cin >> n >> m;
	for(int i = 0;i <= n; ++i) pre[i] = i;
	while(m--){
		cin >> x >> y >>z;
		mix(x,y);
	}
	int res = 0;
	for(int i = 1;i <= n; ++i){
		int fa = Find(i);
		if(vis[fa]) continue;
		res++;
		vis[fa] = 1;
	}
	cout << res << '\n';
	return 0;
}