#include <bits/stdc++.h>
const int N = 200333;
using namespace std;
int n, m, fa[N], ans;
map<int, vector<pair<int, int> > > M;
int find(int u) {
  if (fa[u] == u) return u;
  return fa[u] = find(fa[u]);
}
void merge(int u, int v) {
  int tx = find(u), ty = find(v);
  if (tx != ty) fa[tx] = ty;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int u, v, w, i = 1; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    M[w].push_back({u, v});
  }
  for (auto A : M) {
    int tmp = 0;
    for (auto B : A.second) {
      if (find(B.first) != find(B.second)) ++tmp;
    }
    for (auto B : A.second) {
      if (find(B.first) != find(B.second)) merge(B.first, B.second), --tmp;
    }
    ans += tmp;
  }
  printf("%d\n", ans);
}
