#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
class UnionFindTree {
 private:
  vector<int> par, rank;

 public:
  UnionFindTree(int n) {
    par = rank = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 greater<tuple<int, int, int>>>
      q;
  for (int i = 0; i < (M); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    if (a > b) swap(a, b);
    q.emplace(c, a, b);
  }
  int ans = 0;
  UnionFindTree uf(N);
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int a = get<1>(t), b = get<2>(t);
    if (uf.same(a, b))
      ans++;
    else
      uf.unite(a, b);
  }
  cout << ans << endl;
}
