#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n;
vector < int > v[300100];
bool vis[300100];

void DFS(int x){

    vis[x] = true;
    for(auto j : v[x]){
        if(!vis[j])  DFS(j);
    }
}

int main()
{

    int n , m;  cin >> n >> m;
    for(int i = 0;i<m;i++){
        int x,y,z;  cin >> x >> y >> z;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int Ans = 0;
    for(int i = 1;i<=n;i++){
        if(!vis[i]){
            Ans++;
            DFS(i);
        }
    }
    cout << Ans;
    return 0;
}
