#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int N, M, H, L, R;
int P[MAXN];
pair<int, pair<int, int> > A[MAXN];
int find(int x) {
  if (P[x] != x) {
    P[x] = find(P[x]);
  }
  return P[x];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i].second.first >> A[i].second.second >> A[i].first;
  }
  for (int i = 1; i <= N; i++) {
    P[i] = i;
  }
  sort(A, A + M);
  while (L < M) {
    if (A[L].first == A[R].first) {
      if (find(A[R].second.first) != find(A[R].second.second)) {
        H++;
      }
      R++;
    } else {
      if (find(A[L].second.first) != find(A[L].second.second)) {
        H--;
        P[find(A[L].second.first)] = find(A[L].second.second);
      }
      L++;
    }
  }
  cout << H << '\n';
  return 0;
}
