#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
int n, m, cha[N], d[N];
struct edge {
  int x, y, w;
  bool operator<(const edge &other) const { return w < other.w; }
} c[N];
int tim(int x) { return cha[x] == x ? x : tim(cha[x]); }
void hop(int u, int v) {
  u = tim(u);
  v = tim(v);
  if (d[u] > d[v]) {
    d[u]++;
    cha[v] = u;
  } else {
    d[v]++;
    cha[u] = v;
  }
}
int main() {
  int res = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d %d", &c[i].x, &c[i].y, &c[i].w);
  sort(c + 1, c + m + 1);
  for (int i = 1; i <= n; i++) cha[i] = i;
  for (int i = 1; i <= m; i++) {
    if (i == 1 || c[i].w != c[i - 1].w)
      for (int j = i; j <= m && c[j].w == c[i].w; j++)
        if (tim(c[j].x) != tim(c[j].y)) res++;
    if (tim(c[i].x) != tim(c[i].y)) {
      hop(c[i].x, c[i].y);
      res--;
    }
  }
  cout << res;
}
