#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

const int MAXM = (int)1e5 + 5;

int x[MAXM];
int y[MAXM];
int z[MAXM];

vector<int> edges[MAXM];
bool vis[MAXM];

void dfs(int i) {
    vis[i] = true;
    for (auto to: edges[i]) {
        if (!vis[to]) {
            dfs(to);
        }
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d%d", &x[i], &y[i], &z[i]);
        edges[x[i]].push_back(y[i]);
        edges[y[i]].push_back(x[i]);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            ans++;
            dfs(i);
        }
    }
    printf("%d\n", ans);
}
