#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, maxm = 2e5 + 10;
struct Edge {
  int u, v, w;
  bool operator<(const Edge &rsh) const { return w < rsh.w; }
} G[maxn];
int pre[maxn], N, M;
int getPre(int i) { return i == pre[i] ? i : pre[i] = getPre(pre[i]); }
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; ++i) pre[i] = i;
  for (int i = 0; i < M; ++i) {
    Edge &now = G[i];
    scanf("%d%d%d", &now.u, &now.v, &now.w);
  }
  sort(G, G + M);
  int res = 0;
  for (int i = 0; i < M;) {
    int k = i + 1;
    Edge &now = G[i];
    while (k < M && now.w == G[k].w) ++k;
    int cnt = 0;
    for (int j = i; j < k; ++j) {
      Edge &buf = G[j];
      int fa = getPre(buf.u), fb = getPre(buf.v);
      if (fa != fb) ++cnt;
    }
    for (int j = i; j < k; ++j) {
      Edge &buf = G[j];
      int fa = getPre(buf.u), fb = getPre(buf.v);
      if (fa != fb) {
        pre[fa] = fb;
        --cnt;
      }
    }
    res += cnt;
    i = k;
  }
  printf("%d\n", res);
  return 0;
}
