#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int a[100000], x[100000], y[100000], z[100000], n, m, cnt;

int f(int x) {
  if(x == a[x])
    return x;
  return a[x] = f(a[x]);
}

void con(int p, int t) {
  if(f(p) == f(t))
    return;
  --cnt;
  a[f(p)] = f(t);
}

int main() {
  cin >> n >> m;
  cnt = n;
  for(int i = 0; i < m; ++i)
    cin >> x[i] >> y[i] >> z[i], (--x[i], --y[i]);
  iota(a, a + n, 0);
  for(int i = 0; i < m; ++i)
    con(x[i], y[i]);
  cout << cnt << endl;
}