#include <bits/stdc++.h>
using namespace std;
int cycles = 0;
vector<int> v[101];
int col[101];
void f(int u, int p) {
  if (col[u] == 1) {
    cycles++;
    return;
  }
  if (col[u] == 2) {
    return;
  }
  col[u] = 1;
  for (int i = 0; i < v[u].size(); ++i) {
    int ver = v[u][i];
    if (ver != p) f(ver, u);
  }
  col[u] = 2;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  memset(col, 0, sizeof(col));
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < n; ++i) {
    if (col[i] == 0) {
      f(i, i);
    }
  }
  cout << cycles;
  return 0;
}
