#include <bits/stdc++.h>
using namespace std;
int n, m, fa[200005], ans, num, b[200005];
struct he {
  int l, r, c;
} a[200005];
bool cmp(he a, he b) { return a.c < b.c; }
int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); }
bool check(int l, int r) {
  l = gf(l);
  r = gf(r);
  if (l == r) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].c);
  }
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int j;
    for (j = i; j <= m; j++)
      if (a[i].c != a[j].c) {
        j = j - 1;
        break;
      }
    int cnt = 0;
    for (int k = i; k <= j; k++)
      if (!check(a[k].l, a[k].r)) {
        b[++cnt] = k;
      }
    for (int k = 1; k <= cnt; k++)
      if (!check(a[b[k]].l, a[b[k]].r)) {
        fa[gf(a[b[k]].l)] = gf(a[b[k]].r);
      } else
        ans++;
    i = j;
  }
  printf("%d\n", ans);
}
