#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct Edge {
  int u, v, w;
  bool operator<(const Edge& rhs) const { return w < rhs.w; }
};
Edge edge[maxn];
int fa[maxn];
int get(int x) {
  if (x == fa[x]) return x;
  return fa[x] = get(fa[x]);
}
bool merge(int x, int y) {
  int tmp1 = get(x);
  int tmp2 = get(y);
  if (tmp1 == tmp2) return 0;
  fa[tmp1] = tmp2;
  return 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
  }
  sort(edge + 1, edge + 1 + m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int ans = 0, sum = 0;
  for (int i = 1; i <= m; i++) {
    int j = i;
    while (edge[j + 1].w == edge[j].w) j++;
    sum = j - i + 1;
    for (int k = i; k <= j; k++) {
      if (get(edge[k].u) == get(edge[k].v)) sum--;
    }
    for (int k = i; k <= j; k++) {
      sum -= merge(edge[k].u, edge[k].v);
    }
    ans += sum;
    i = j;
  }
  printf("%d\n", ans);
}
