#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define lim 1000000
using namespace std;
typedef pair<int, int> ii;
vector <vector<int> > Adj;
int check[100001]={0};
ll res=0;
void dfs(ll i) {
	check[i]=1;
	for(int x=0; x<(int)Adj[i].size(); x++) {
		if(check[Adj[i][x]]==0) dfs(Adj[i][x]);
	}
}

signed main() {
	ll n, m;
	cin >> n >> m;
	ll x[m], y[m], z[m];
	Adj.assign(n+1, vector<int>());
	for(int i=0; i<m; i++) {
		cin >> x[i] >> y[i] >> z[i];
		if(x[i]>y[i]) Adj[y[i]].push_back(x[i]);
		else Adj[x[i]].push_back(y[i]);
	}
//	for(int i=1; i<=Adj.size(); i++) {
//		for(int j=0; j<Adj[i].size(); j++) {
//			cout << Adj[i][j] << " ";
//		}
//		cout << endl;
//	}
	for(int i=1; i<=n; i++) {
		if(check[i]==0) {
			dfs(i);
			res++;
		}
	}
	cout << res;
}