#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DUMP(var) std::cout << #var " = " << var << std::endl;

#define PRINT(os, c)                              \
  do {                                            \
    os << "[ ";                                   \
    for (auto i = c.begin(); i != c.end(); i++) { \
      if (i != c.begin()) {                       \
        os << ", ";                               \
      }                                           \
      os << *i;                                   \
    }                                             \
    os << " ]";                                   \
    return os;                                    \
  } while (0)
#define PRINT_MAP(os, c)                          \
  do {                                            \
    os << "{ ";                                   \
    for (auto i = c.begin(); i != c.end(); i++) { \
      if (i != c.begin()) {                       \
        os << ", ";                               \
      }                                           \
      os << (*i).first << " => " << (*i).second;  \
    }                                             \
    os << " }";                                   \
    return os;                                    \
  } while (0)
#define PRINT_SET(os, c)                          \
  do {                                            \
    os << "( ";                                   \
    for (auto i = c.begin(); i != c.end(); i++) { \
      if (i != c.begin()) {                       \
        os << ", ";                               \
      }                                           \
      os << *i;                                   \
    }                                             \
    os << " )";                                   \
    return os;                                    \
  } while (0)

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
  PRINT(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::deque<T>& c) {
  PRINT(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::list<T>& c) {
  PRINT(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::forward_list<T>& c) {
  PRINT(os, c);
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& c) {
  PRINT_MAP(os, c);
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::multimap<T, U>& c) {
  PRINT_MAP(os, c);
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::unordered_map<T, U>& c) {
  PRINT_MAP(os, c);
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os,
                         const std::unordered_multimap<T, U>& c) {
  PRINT_MAP(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& c) {
  PRINT_SET(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::multiset<T>& c) {
  PRINT_SET(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T>& c) {
  PRINT_SET(os, c);
}
template <typename T>
std::ostream& operator<<(std::ostream& os,
                         const std::unordered_multiset<T>& c) {
  PRINT_SET(os, c);
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  os << "< " << p.first << ", " << p.second << " >";
  return os;
}
template <typename T>
class UnionFind {
 public:
  int find(const T& a);
  bool unite(const T& a, const T& b);
  bool same(const T& a, const T& b);
  int findById(int id);
 private:
  map<T, int> mMap;
  int mId;
  deque<int> mParent;
  deque<int> mRank;

};

template <typename T>
int UnionFind<T>::findById(int id) {
  if (id == mParent[id]) return id;
  return mParent[id] = findById(mParent[id]);
}

template <typename T>
int UnionFind<T>::find(const T& a) {
  int id = 0;
  if (!mMap.count(a)) {
    id = mId++;
    mMap[a] = id;
    mParent.push_back(id);
    mRank.push_back(0);
  }
  id = mMap[a];
  return findById(id);
}

template <>
int UnionFind<int>::find(const int& a) {
  if (mParent.size() <= (unsigned int)a) {
    for (int i = mParent.size(); i <= a; i++) {
      mParent.push_back(i);
      mRank.push_back(0);
    }
  }
  return findById(a);
}

template <typename T>
bool UnionFind<T>::unite(const T& a, const T& b) {
  int id_a = find(a);
  int id_b = find(b);
  if (id_a == id_b) return false;

  if (mRank[id_a] < mRank[id_b]) {
    mParent[id_a] = id_b;
  } else {
    mParent[id_b] = id_a;
    if (mRank[id_a] == mRank[id_b]) mRank[id_a]++;
  }
  return true;
}

template <typename T>
bool UnionFind<T>::same(const T& a, const T& b) {
  return find(a) == find(b);
}



int main() {
  int N,M;
  cin>>N>>M;
  UnionFind<int> uf;
  uf.find(N);
  REP(i,M){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    uf.unite(X,Y);
  }
  set<int> ans;
  for(int i =1 ;i<=N;i++){
    ans.insert(uf.findById(i));
  }
  cout<<ans.size()<<endl;
  
    
    
  return 0;
}




Measured memory_bytes: 5760