#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct node {
  int u, v, w;
  bool operator<(const node &b) const { return w < b.w; }
};
node a[N];
int f[N], n, m;
void init() {
  for (int i = 1; i <= n; i++) f[i] = i;
}
int Find(int x) {
  if (x == f[x])
    return x;
  else
    return f[x] = Find(f[x]);
}
void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  if (x != y) f[y] = x;
}
int main() {
  scanf("%d %d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i].u, &a[i].v, &a[i].w);
  }
  sort(a + 1, a + 1 + m);
  int ans = 0, pos = 1;
  for (int i = 1; i <= m; i++) {
    int x = Find(a[i].u), y = Find(a[i].v);
    if (x != y) ans++;
    if (a[i].w != a[i + 1].w) {
      for (int j = pos; j <= i; j++) {
        Merge(a[j].u, a[j].v);
      }
      pos = i + 1;
    }
  }
  printf("%d\n", ans - (n - 1));
  return 0;
}
