#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
struct EDGE {
  int u, v, val, flag;
  void read() { scanf("%d %d %d", &u, &v, &val); }
} e[N];
int n, m, ans, fa[N];
int cmp(EDGE a, EDGE b) { return a.val < b.val; }
inline int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) e[i].read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(e + 1, e + 1 + m, cmp);
  for (int i = 1, nex = 1; i <= m;) {
    if (getfa(e[i].u) != getfa(e[i].v)) e[i].flag = 1;
    while (nex < m && e[nex + 1].val == e[i].val) {
      ++nex;
      if (getfa(e[nex].u) != getfa(e[nex].v)) e[nex].flag = 1;
    }
    for (int x, y; i <= nex; i++) {
      x = getfa(e[i].u), y = getfa(e[i].v);
      if (x == y) {
        ans += e[i].flag;
        continue;
      }
      fa[y] = x;
    }
  }
  printf("%d\n", ans);
  return 0;
}
