#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
struct DisjointSet {
  int rank{};
  DisjointSet *p{};
  DisjointSet *repr() {
    if (p != this) p = p->repr();
    return p;
  }
  void init() {
    p = this;
    rank = 0;
  }
  void unite(DisjointSet &that) {
    auto a = repr();
    auto b = that.repr();
    if (a == b) return;
    if (a->rank > b->rank)
      b->p = a;
    else
      a->p = b;
    if (a->rank == b->rank) b->rank++;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<DisjointSet> sets(n);
  for (auto &s : sets) s.init();
  map<int64, vector<pair<int, int>>> M;
  for (int i = 0; i < m; i++) {
    int a, b;
    int64 w;
    cin >> a >> b >> w;
    a--;
    b--;
    M[w].push_back({a, b});
  }
  int64 ans{};
  for (auto &[w, E] : M) {
    int64 Q{}, q{};
    for (auto [i, j] : E) {
      auto a = sets[i].repr();
      auto b = sets[j].repr();
      if (a != b) Q++;
    }
    for (auto [i, j] : E) {
      auto a = sets[i].repr();
      auto b = sets[j].repr();
      if (a != b) {
        q++;
        a->unite(*b);
      }
    }
    ans += Q - q;
  }
  cout << ans << endl;
}
