#include<cstdio>
const int N = 1e5+5;
int p[N];
int vis[N];

int get(int u){
    if(p[u]==u) return u;
    else return p[u] = get(p[u]);
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) vis[i] = 0, p[i] = i;
    while(m--){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        int x = get(u), y = get(v);
        p[x] = y;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int x = get(i);
        if(!vis[x]){
            ans++;
            vis[x] = 1;
        }
    }
    printf("%d\n",ans);
    return 0;
}