#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;
int n, m, a, b, c;
int p[mx];

void ufini(int n){ fill(p, p+n, -1);}
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
void uni(int x, int y){
    x = find(x); y = find(y);
    if(x != y){
        if(x < y) swap(x, y);
        p[x] += p[y];
        p[y] = x;
        n--;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    ufini(n+3);
    for(int i = 0; i < m; i++){
        scanf("%d%d%d", &a, &b, &c);
        uni(a, b);
    }
    printf("%d\n", n);
}