#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int mxsz = 1e5 + 3;
int n, m;
int par[mxsz];
int fpr(int u){return par[u] == u ? u : par[u] = fpr(par[u]);}
void merge(int u, int v){ par[fpr(v)] = fpr(u);}

int main(){
	cin >> n >> m;
	for (int i = 1; i <= n; i++) par[i] = i;
	for (int i = 1, u, v, z; i <= m; i++){
		cin >> u >> v >> z;
		merge(u, v);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++){
		if (fpr(i) == i) cnt++;
	}
	cout << cnt << '\n';
	return 0;
}
