#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<int>graph[],int start,long int v,int visit[])
{
	int i;
	if(visit[start]==0)
	{
		visit[start]=1;
		for(i=0;i<graph[start].size();++i)
		{
			if(visit[graph[start][i]]==0)
				dfs(graph,graph[start][i],v,visit);
		}
	}	
}
int main()
{
	int n,m,i,count=0;
	scanf("%d %d",&n,&m);
	int x,y,z,visit[n+1];
	vector<int> graph[n+1];
	for(i=0;i<m;++i)
	{
		scanf("%d %d %d",&x,&y,&z);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	for(i=1;i<=n;++i)
		visit[i]=0;
	for(i=1;i<=n;++i)
	{
		if(visit[i]==0)
		{
			dfs(graph,i,n,visit);
			++count;
		}
	}
	printf("%d",count);
}