#include <bits/stdc++.h>
using namespace std;
int pre[int(2e5) + 100];
int n, m;
struct node {
  int fr, to, dis;
} edge[int(2e5) + 100];
void init() {
  for (int i = 0; i <= n; i++) pre[i] = i;
}
int find(int x) {
  if (x == pre[x])
    return x;
  else
    return pre[x] = find(pre[x]);
}
void join(int a, int b) {
  int x = find(a);
  int y = find(b);
  if (x != y) {
    pre[x] = y;
  }
}
int cmp(node a, node b) { return a.dis < b.dis; }
int main() {
  scanf("%d%d", &(n), &(m));
  init();
  int ans = 0;
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &edge[i].fr, &edge[i].to, &edge[i].dis);
  sort(edge, edge + m, cmp);
  for (int i = 0; i < m;) {
    int num = 0;
    int j = i;
    while (edge[j].dis == edge[i].dis) j++;
    for (int k = i; k < j; ++k) {
      if (find(edge[k].fr) != find(edge[k].to)) {
        num++;
      }
    }
    for (int k = i; k < j; ++k) {
      if (find(edge[k].fr) != find(edge[k].to)) {
        join(find(edge[k].fr), find(edge[k].to));
        num--;
      }
    }
    ans += num;
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
