#include <iostream>
#include <vector>
using namespace std;

int N, M, X[1 << 18], Y[1 << 18], Z[1 << 18];
vector<int> G[1 << 18];
bool used[1 << 18];

void dfs(int pos) {
	if (used[pos] == true) return;
	used[pos] = true;
	for (int i : G[pos]) dfs(i);
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> X[i] >> Y[i] >> Z[i];
		G[X[i]].push_back(Y[i]);
		G[Y[i]].push_back(X[i]);
	}
	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		if (used[i] == true) continue;
		cnt++; dfs(i);
	}
	cout << cnt << endl;
	return 0;
}