#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
  int u, v;
  int w;
  bool friend operator<(node a, node b) { return a.w < b.w; }
} _edge[maxn];
int pre[maxn];
int _find(int x) {
  if (pre[x] == x) return x;
  pre[x] = _find(pre[x]);
  return pre[x];
}
int kruscal(int n, int m) {
  int num = 0;
  for (int i = 1; i <= n; i++) pre[i] = i;
  int j = 1, u, v, w, fu, fv;
  for (int i = 1; i <= m;) {
    while (_edge[i].w == _edge[j].w) j++;
    for (int k = i; k < j; k++) {
      u = _edge[k].u;
      v = _edge[k].v;
      fu = _find(u);
      fv = _find(v);
      if (fu != fv) num++;
    }
    for (int k = i; k < j; k++) {
      u = _edge[k].u;
      v = _edge[k].v;
      fu = _find(u);
      fv = _find(v);
      if (fu != fv) {
        pre[fu] = fv;
        num--;
      }
    }
    i = j;
  }
  return num;
}
int main() {
  int u, v, n, m;
  long long int w;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    _edge[i].u = u;
    _edge[i].v = v;
    _edge[i].w = w;
  }
  sort(_edge + 1, _edge + m + 1);
  printf("%d\n", kruscal(n, m));
  return 0;
}
