#include <bits/stdc++.h>
using namespace std;
vector<int> p, rk;
int getp(int v) {
  if (v == p[v]) return v;
  return p[v] = getp(p[v]);
}
bool merge(int v, int u) {
  u = getp(u);
  v = getp(v);
  if (u == v) return false;
  if (rk[u] < rk[v]) swap(u, v);
  rk[u] += rk[v];
  p[v] = u;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  p = vector<int>(n);
  iota(p.begin(), p.end(), 0);
  rk = vector<int>(n, 1);
  vector<pair<pair<int, int>, int>> e(m);
  for (int i = 0; i < m; ++i) {
    cin >> e[i].first.first >> e[i].first.second >> e[i].second;
    --e[i].first.first;
    --e[i].first.second;
  }
  sort(e.begin(), e.end(),
       [](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
         return a.second < b.second;
       });
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    int j = i;
    while (j < m && e[i].second == e[j].second) {
      ++j;
    }
    int cnt = j - i;
    for (int k = i; k < j; ++k) {
      if (getp(e[k].first.first) == getp(e[k].first.second)) {
        --cnt;
      }
    }
    for (int k = i; k < j; ++k) {
      cnt -= merge(e[k].first.first, e[k].first.second);
    }
    ans += cnt;
    i = j - 1;
  }
  cout << ans << endl;
  return 0;
}
