#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int n,m,cnt;
int f[MAXN];
int find(int x){
	if(x == f[x])
	    return x;
	else
	    return f[x] = find(f[x]);
}
int main()
{
	cin>>n>>m;
	for(int i = 1;i <= n;i++)
	    f[i] = i;	
	while(m--){
		int x,y,z;
		cin>>x>>y>>z;
		int fx = find(x);
		int fy = find(y);
		if(fx != fy){
			f[fx] = fy;
			cnt++;
		}
	}
	cout<<n-cnt<<endl;
}