#include <bits/stdc++.h>
int par[110];
int rank[110];
void init(int N) {
  for (int i = 1; i <= N; i++) {
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rank[y] > rank[x]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[y] == rank[x]) rank[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  std::priority_queue<std::tuple<int, int, int>,
                      std::vector<std::tuple<int, int, int>>,
                      std::greater<std::tuple<int, int, int>>>
      pq;
  int N, M;
  std::cin >> N >> M;
  init(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    pq.push(std::tuple<int, int, int>{c, a, b});
  }
  while (!pq.empty()) {
    int a, b, c;
    std::tuple<int, int, int> t = pq.top();
    pq.pop();
    std::tie(a, b, c) = t;
    if (!same(b, c)) {
      unite(b, c);
      M--;
    }
  }
  std::cout << M << std::endl;
  return 0;
}
