#include <bits/stdc++.h>
using namespace std;
const long long int M = 2e5 + 10;
const long long int mod = 1e9 + 7;
const long long int infi = LLONG_MAX;
long long int ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, c, z,
                                  sum;
long long int parent[M];
long long int csize[M], val[M];
priority_queue<pair<long long int, pair<long long int, long long int>>,
               vector<pair<long long int, pair<long long int, long long int>>>,
               greater<pair<long long int, pair<long long int, long long int>>>>
    pq;
long long int find_parent(long long int node) {
  if (parent[node] != node) {
    parent[node] = find_parent(parent[node]);
  }
  return parent[node];
}
long long int merge(long long int x, long long int y) {
  x = find_parent(x);
  y = find_parent(y);
  if (csize[x] < csize[y]) {
    parent[x] = y;
    csize[y] += csize[x];
    return y;
  } else {
    parent[y] = x;
    csize[x] += csize[y];
    return x;
  }
}
bool check(long long int cx, long long int cy) {
  return (find_parent(cx) != find_parent(cy));
}
int main() {
  long long int i, j;
  scanf("%lld %lld", &n, &m);
  for (i = 1; i < n + 1; i++) parent[i] = i, csize[i] = 1;
  for (i = 1; i < m + 1; i++) {
    scanf("%lld %lld %lld", &x, &y, &z);
    if (x > y) swap(x, y);
    pq.push({z, {x, y}});
  }
  long long int ans = 0;
  while (!pq.empty()) {
    vector<pair<long long int, pair<long long int, long long int>>> v;
    long long int cw = pq.top().first, cx, cy;
    while (!pq.empty() && pq.top().first == cw) {
      auto top_it = pq.top();
      cx = top_it.second.first, cy = top_it.second.second;
      pq.pop();
      if (check(cx, cy)) {
        v.push_back({cw, {cx, cy}});
      }
    }
    for (auto point : v) {
      if (check(point.second.first, point.second.second) == false) {
        ans++;
        pq.push(point);
      } else {
        merge(point.second.first, point.second.second);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
