#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, M; vector G; vi vis; void dfs(int u, int p){ if(vis[u]++)return; each(v, G[u])if(v != p&&!vis[v])dfs(v, u); } int main(){ while(cin >> N >> M){ G = vector(N); rep(i, M){ int a, b, c; scanf("%d%d%d", &a, &b, &c); --a; --b; G[a].push_back(b); G[b].push_back(a); } int ans = 0; vis = vi(N); rep(i, N){ if(!vis[i]){ dfs(i, -1); ans++; } } cout << ans << endl; } }