#include <iostream>
using namespace std;
int p[100005]={0};

int find(int a){
    if(p[a]==a)
        return a;
    return p[a] = find(p[a]);
}
void disjoint(int a, int b){
    p[find(p[b])] = find(p[a]);
}

int main() {
    
    int poke,q,tmp;
    cin>>poke>>q;
    for(int i=0;i<=poke;i++){
        p[i] = i;
    }
    int n,m;
    for(int i=0;i<q;i++){
        cin>>n>>m>>tmp;
        disjoint(n,m);
    }
    int ans = 0;
    for(int i=1;i<=poke;i++)
        if(find(i)==i)ans++;
    cout<<ans<<endl;
    return 0;
}