#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long dsu[N];
long long root(long long n) {
  while (n != dsu[n]) dsu[n] = dsu[dsu[n]], n = dsu[n];
  return n;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) dsu[i] = i;
  map<long long, vector<pair<long long, long long> > > mp;
  while (m--) {
    long long u, v, w;
    cin >> u >> v >> w;
    mp[w].push_back({u, v});
  }
  long long res = 0;
  for (auto i : mp) {
    vector<pair<long long, long long> > pal;
    for (auto j : i.second)
      if (root(j.first) != root(j.second)) pal.push_back(j);
    for (auto j : pal)
      if (root(j.first) == root(j.second))
        res++;
      else
        dsu[root(j.first)] = root(j.second);
  }
  cout << res;
  return 0;
}
