#include <bits/stdc++.h>
using namespace std;
int z[110];
struct edg {
  int u, v, w;
} x[10010];
void Init(int n) {
  for (int i = 0; i <= n; i++) z[i] = i;
}
int find1(int a) {
  if (z[a] == a)
    return a;
  else {
    int b = find1(z[a]);
    return z[a] = b;
  }
}
bool cmp(edg a, edg b) { return a.w < b.w; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  Init(n);
  for (int i = 0; i < m; i++) scanf("%d%d%d", &x[i].u, &x[i].v, &x[i].w);
  sort(x, x + m, cmp);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int fa, fb;
    fa = find1(x[i].u);
    fb = find1(x[i].v);
    if (fa != fb)
      z[fa] = z[fb];
    else
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
