#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, w;
} e[200005];
int fa[200005];
inline int ff(int x) {
  if (fa[x] == x) return x;
  return fa[x] = ff(fa[x]);
}
inline bool cmp(edge x, edge y) { return x.w < y.w; }
int main(int argc, char** argv) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) cin >> e[i].u >> e[i].v >> e[i].w;
  sort(e + 1, e + m + 1, cmp);
  int now = 0, ans = 0;
  for (int i = 1; i <= m; i++) {
    if (e[i].w != e[i - 1].w) {
      now = i;
      do {
        if (e[now].w != e[now + 1].w) break;
      } while (++now);
      for (int j = i; j <= now; j++)
        if (ff(e[j].u) != ff(e[j].v)) ++ans;
      for (int j = i; j <= now; j++) {
        if (ff(e[j].u) != ff(e[j].v)) {
          --ans;
          fa[ff(e[j].u)] = ff(e[j].v);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
