#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

struct UnionFind {
public:
  std::vector<ll> par;
  std::vector<ll> rank;
  std::vector<ll> size;
  std::vector<ll> diff_weight;

  UnionFind(ll N){
    par         = std::vector<ll>(N+1, 0LL);
    rank        = std::vector<ll>(N+1, 0LL);
    size        = std::vector<ll>(N+1, 1LL);
    diff_weight = std::vector<ll>(N+1, 0LL);
    for (ll i = 0; i <= N; i++) par[i] = i;
  }

  ll find(ll x){
    if (par[x] == x) return x;
    ll root = find(par[x]);
    diff_weight[x] += diff_weight[par[x]];
    par[x] = root;
    return root;
  }

  void unite(ll x, ll y, ll w) {
    w += get_weight(x);
    w -= get_weight(y);

    x = find(x);
    y = find(y);
    if (x == y) return;

    size[x] += size[y];
    size[y] = size[x];

    if (rank[x] < rank[y]) std::swap(x, y), w = -w;
    if (rank[x] == rank[y]) rank[x]++;

    par[y] = x;
    diff_weight[y] = w;
    //print(x, y, diff_weight[x], diff_weight[y]);

    return;
  }

  bool is_same(ll x, ll y){
    return find(x) == find(y);
  }

  ll get_size(ll x){
    return size[find(x)];
  }

  ll get_weight(ll x){
    find(x);
    return diff_weight[x];
  }

  ll get_diff(ll x, ll y){
    //print("diff", y, x, get_weight(y), get_weight(x));
    return get_weight(y) - get_weight(x);
  }
};

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, M;
  std::cin >> N >> M;

  UnionFind uf(N);

  for (ll i = 0; i < M; i++) {
    ll x, y, z;
    std::cin >> x >> y >> z;
    x--; y--;
    uf.unite(x, y, 0LL);
  }

  std::map< ll, bool > mc;
  for (ll i = 0; i < N; i++) {
    ll root = uf.find(i);
    mc[root] = true;
  }

  ll ans = mc.size();
  print(ans);

  return 0;
}


Measured memory_bytes: 9600