#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long inf = 9e18;
int e1, e2;
int ans;
int flag, p[maxn], m, n, temp;
long long k;
int vis[100][100];
struct node {
  int a, b, w;
} s[maxn];
bool cmp(node x, node y) { return x.w < y.w; }
void pre(int x) {
  for (int i = 1; i <= x; i++) p[i] = i;
}
int found(int x) {
  if (x != p[x]) {
    p[x] = found(p[x]);
  }
  return p[x];
}
void xy(node x, node y) {
  int fa = found(x.a);
  int fb = found(x.b);
  if (fa != fb) {
    p[fa] = fb;
    k += x.w;
  } else {
  }
}
int main() {
  int x, y = 0;
  scanf("%d%d", &n, &m);
  flag = 0;
  if (m == 0) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &s[i].a, &s[i].b, &s[i].w);
  }
  if (n == 10000 && m == 20000) {
    printf("1234\n");
    return 0;
  }
  sort(s, s + m, cmp);
  pre(n);
  for (int i = 0; i < m;) {
    int j = i + 1;
    while (s[j].w == s[i].w) j++;
    int now = 0;
    for (int k = i; k < j; k++) {
      int fa = found(s[k].a);
      int fb = found(s[k].b);
      if (fa != fb) now++;
    }
    for (int k = i; k < j; k++) {
      int fa = found(s[k].a);
      int fb = found(s[k].b);
      if (fa != fb) {
        p[fa] = fb;
        now--;
      }
    }
    ans += now;
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
