/*input
100000 1
1 100000 100
*/
#include "bits/stdc++.h"
using namespace std;
long long x[100005],y[100005],z[100005],vis[100005],n;
vector<int> v[100005];
void dfs(int u){
	vis[u] = 1;
	for(auto i:v[u]) if(!vis[i]) dfs(i);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long q,m,k,h,ans=0,sum=0,p;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>x[i]>>y[i]>>z[i];
		v[x[i]].push_back(y[i]);
		v[y[i]].push_back(x[i]);
	}
	for(int i=1;i<=n;++i) if(!vis[i]){
		++ans;
		dfs(i);
	}
	cout<<ans;
}