#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int fa[N];
int n, m;
struct cc {
  int x, y, r;
} edge[N];
int cmp(cc a, cc b) { return a.r < b.r; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> edge[i].x >> edge[i].y >> edge[i].r;
  sort(edge, edge + m, cmp);
  for (int i = 0; i <= n; i++) fa[i] = i;
  int ans = 0;
  for (int i = 0; i < m;) {
    int j = i;
    int num = 0;
    while (edge[i].r == edge[j].r) j++;
    for (int k = i; k < j; k++) {
      int x = find(edge[k].x);
      int y = find(edge[k].y);
      if (x != y) num++;
    }
    for (int k = i; k < j; k++) {
      int x = find(edge[k].x);
      int y = find(edge[k].y);
      if (x != y) {
        fa[x] = y;
        num--;
      }
    }
    i = j;
    ans += num;
  }
  cout << ans << endl;
  return 0;
}
