#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, w;
} edge[200222];
int par[200022];
int find(int node) {
  if (par[node] == node) return node;
  return par[node] = find(par[node]);
}
bool cmp(struct node a, struct node b) { return a.w < b.w; }
set<int> s;
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) par[i] = i;
  for (i = 0; i < m; i++) scanf("%d%d%d", &edge[i].a, &edge[i].b, &edge[i].w);
  sort(edge, edge + m, cmp);
  int ans = 0;
  for (i = 0; i < m;) {
    s.clear();
    vector<pair<int, int> > v;
    int j = i, c = 0;
    while (j < m && edge[j].w == edge[i].w) {
      int a = edge[j].a, b = edge[j].b;
      int pa = find(a), pb = find(b);
      if (pa > pb) swap(pa, pb);
      if (pa != pb) v.push_back(make_pair(a, b));
      j++;
    }
    i = j;
    for (j = 0; j < v.size(); j++) {
      int pa = find(v[j].first), pb = find(v[j].second);
      if (pa == pb)
        ans++;
      else
        par[pb] = pa;
    }
  }
  cout << ans << endl;
  return 0;
}
