#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
using plong = pair<ll, ll>;
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n, -1) {}
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) { return -par[root(x)]; }
};
vector<pair<pair<ll, ll>, ll>> v;
bool cmp(pair<pair<ll, ll>, ll> v1, pair<pair<ll, ll>, ll> v2) {
  return v1.second < v2.second;
}
int main() {
  ll N, M;
  cin >> N >> M;
  UnionFind uf(N);
  v.resize(M);
  for (ll i = 0; i < M; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v[i] = make_pair(make_pair(a, b), c);
  }
  sort(v.begin(), v.end(), cmp);
  ll link = 0;
  for (ll i = 0; i < M; i++) {
    if (uf.root(v[i].first.first) == uf.root(v[i].first.second)) continue;
    uf.merge(v[i].first.first, v[i].first.second);
    link++;
  }
  cout << M - link << endl;
}
