#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int mpow(int a, int b, int p = MOD) {
  a = a % p;
  int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b = b >> 1;
  }
  return res % p;
}
const int N = 1e5 + 2;
int p[N];
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
bool add(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return false;
  p[x] = y;
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> v;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    v.push_back({z, {x, y}});
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  sort((v).begin(), (v).end());
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (add(v[i].second.first, v[i].second.second)) {
    } else
      ans++;
  }
  cout << ans;
}
