#include <bits/stdc++.h>
using namespace std;
int n, m, t, a, b, c, sum, x, y, tik;
int fa[200005];
struct edge {
  int u, v, w;
} e[200005];
int cmp(edge a, edge b) { return a.w < b.w; }
int findset(int x) {
  int r = x;
  while (r != fa[r]) r = fa[r];
  int i, j;
  i = x;
  while (i != r) {
    j = fa[i];
    fa[i] = r;
    i = j;
  }
  return r;
}
int main() {
  scanf("%d%d", &n, &m);
  sum = 0;
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(e + 1, e + m + 1, cmp);
  tik = 0;
  for (int i = 1, j = 1; i <= m; i = j) {
    while (j <= m && e[j].w == e[i].w) ++j;
    int cnt = j - i;
    for (int k = i; k < j; k++) {
      int x = findset(e[k].u);
      int y = findset(e[k].v);
      if (x == y) cnt--;
    }
    for (int k = i; k < j; k++) {
      int x = findset(e[k].u);
      int y = findset(e[k].v);
      if (x == y) continue;
      cnt--;
      fa[x] = y;
    }
    sum += cnt;
  }
  printf("%d\n", sum);
  return 0;
}
