#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MIN = INT_MIN;
const long long LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;
int root(int x);
void unite(int x, int y);
int Kruskal();
vector<int> r(SIZE);
vector<pair<int, pair<int, int> > > v;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; ++i) r[i] = i;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    v.push_back(make_pair(c, make_pair(a, b)));
  }
  cout << Kruskal() << '\n';
  return 0;
}
int root(int x) {
  if (x == r[x]) return x;
  return r[x] = root(r[x]);
}
void unite(int x, int y) {
  int rx, ry;
  rx = root(x);
  ry = root(y);
  if (rx < ry) {
    r[ry] = rx;
  } else {
    r[rx] = ry;
  }
}
int Kruskal() {
  int res = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); ++i) {
    pair<int, pair<int, int> > p = v[i];
    if (root(p.second.first) != root(p.second.second)) {
      unite(p.second.first, p.second.second);
    } else {
      ++res;
    }
  }
  return res;
}
