#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
map<int, vector<pair<int, int> > > edge;
int par[MAXN];
int find(int x) {
  if (par[x] == x) return par[x];
  return par[x] = find(par[x]);
}
void join(int x, int y) { par[find(x)] = find(y); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, u, v, w, cost = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    edge[w].push_back({u, v});
  }
  for (map<int, vector<pair<int, int> > >::iterator it = edge.begin();
       it != edge.end(); ++it) {
    w = it->first;
    vector<pair<int, int> > V = it->second;
    for (auto isi : V) {
      if (find(isi.first) != find(isi.second)) cost++;
    }
    for (auto isi : V) {
      if (find(isi.first) != find(isi.second)) {
        join(isi.first, isi.second);
        cost--;
      }
    }
  }
  cout << cost << '\n';
  return 0;
}
