#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> v[N];
int visited[N];


void dfs(int i) {
	visited[i] = 1;
	for(auto j : v[i]) {
		if(!visited[j]) dfs(j);
	}
}




int main() {
	int n , m ; cin >> n >> m;
	for(int i = 0 ;i < m ;i ++ ) {
		int x,y,z; cin >> x >> y >> z;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	int ans = 0;
	
	for(int i = 1; i <= n; i ++) {
		if(!visited[i]) {
			ans ++;
			dfs(i);
		}
	}
	cout << ans;
	
}
