#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, ans;
int fa[maxn];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]);} 
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) fa[i] = i;
	for(int i = 1; i <= m; ++i)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		x = getfa(x); y = getfa(y);
		if(x != y)
			fa[x] = y;
	}
	for(int i = 1; i <= n; ++i)
		if(fa[i] == i)
			++ans;
	cout << ans << endl;
	return 0;
}
		