#include <bits/stdc++.h>
using namespace std;
vector<long long> p(200011, -1);
long long find(long long x) { return p[x] < 0 ? x : p[x] = find(p[x]); }
void merge(long long x, long long y) {
  if ((x = find(x)) == (y = find(y))) return;
  if (p[y] < p[x]) swap(x, y);
  p[x] += p[y];
  p[y] = x;
}
struct edge {
  long long u, v, w;
};
bool operator<(const edge &e1, const edge &e2) { return e1.w > e2.w; }
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  priority_queue<edge> q;
  for (long long i = 0; i < m; ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    q.push({u, v, w});
  }
  long long ans = 0;
  while (!q.empty()) {
    edge curr = q.top();
    q.pop();
    vector<edge> currEdges;
    if (find(curr.u) != find(curr.v)) {
      currEdges.push_back(curr);
    }
    while (!q.empty() && q.top().w == curr.w) {
      if (find(q.top().u) != find(q.top().v)) {
        currEdges.push_back(q.top());
      }
      q.pop();
    }
    for (edge curr : currEdges) {
      if (find(curr.u) != find(curr.v)) {
        merge(curr.u, curr.v);
      } else {
        ans++;
        curr.w++;
        q.push(curr);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
