#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 1e6;
vector<long long> child, tree(NMAX);
long long root(long long i) {
  if (i == tree[i]) {
    for (long long j = (0); j < (child.size()); j++) tree[child[j]] = i;
    child.clear();
    return i;
  } else {
    child.push_back(i);
    return i = root(tree[i]);
  }
}
long long unit(long long x, long long y) {
  x = root(x);
  y = root(y);
  tree[max(x, y)] = min(x, y);
}
bool isUnit(long long x, long long y) { return root(x) == root(y); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, pair<long long, long long>>> edge(m);
  for (long long i = (0); i < (m); i++) {
    long long x, y, cost;
    cin >> x >> y >> cost;
    edge[i] = make_pair(cost, pair<long long, long long>(x - 1, y - 1));
  }
  sort(edge.begin(), edge.end());
  long long ans = 0, cur = 0;
  for (long long i = (0); i < (n); i++) tree[i] = i;
  long long i = 0;
  while (i < m) {
    cur = edge[i].first;
    vector<pair<long long, long long>> tmp;
    while (i < m && cur == edge[i].first) {
      if (!isUnit(edge[i].second.first, edge[i].second.second))
        tmp.push_back(pair<long long, long long>(edge[i].second.first,
                                                 edge[i].second.second));
      i++;
    }
    bool flag = false;
    long long cnt = 0;
    for (auto to : tmp) {
      if (isUnit(to.first, to.second))
        cnt++;
      else
        unit(to.first, to.second), flag = true;
    }
    if (flag) ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
