#include <bits/stdc++.h>
using namespace std;
int rt[100010];
int find( int x ) { return x == rt[x] ? x : rt[x] = find(rt[x]);}
int main() {
	int n, m;scanf("%d%d", &n, &m);
	for( int i = 1 ; i <= n ; ++i ) rt[i] = i;
	for( int i = 0, u, v, w ;  i<m ; ++i ) scanf("%d%d%d", &u, &v, &w), rt[find(u)] = find(v);
	set<int> c;
	for( int i = 1 ; i <= n ; ++i ) c.insert(find(i));
	printf("%lu\n", c.size());
	return 0;
}
