#include <bits/stdc++.h>
using namespace std;

long n,m,ans=0;
map<long,vector<long>> a;
vector<bool> b(100010,true);

void aaa(long x) {
  b[x-1]=false;
  if(a.count(x)) {
    for(long i=0;i<a[x].size();i++) if(b[a[x][i]-1]) aaa(a[x][i]);
  }
}

int main() {
  cin >> n >> m;
  for(long i=0;i<m;i++) {
    long x,y,z;
    cin >> x >> y >> z;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for(long i=1;i<=n;i++) {
    if(b[i-1]) {
      aaa(i);
      ans++;
    }
  }
  cout << ans << endl;
}