#include <bits/stdc++.h>
using namespace std;

#define MAX_N 100005

int n ,m;
int x ,y ,z;

int par[MAX_N];
int fnd(int u){
    return par[u] = (par[u] == u ? u : fnd(par[u]));
}
void unn(int u ,int v){
    u = fnd(u) ,v = fnd(v);
    if(u != v)
        par[u] = v;
}

int main()
{
    scanf("%d%d",&n,&m);
    iota(par ,par+n+1 ,0);
    for(int i=0; i<m; i++){
        scanf("%d%d%d",&x,&y,&z);
        z = (z&1);
        unn(x ,y);
    }

    set <int> ss;
    for(int i=1; i<=n ;i++)
        ss.insert(fnd(i));

    cout << ss.size() << endl;
}
