#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, m, u, v, w, ans, par[N];
map<int, vector<pair<int, int>>> mapp;
int g_par(int v) { return (par[v] == v ? v : par[v] = g_par(par[v])); }
bool merge(int u, int v) {
  if (g_par(u) != g_par(v)) {
    par[g_par(u)] = g_par(v);
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) par[i] = i;
  while (m--) {
    cin >> u >> v >> w;
    mapp[w].push_back(pair<int, int>(--u, --v));
  }
  for (auto P : mapp) {
    vector<pair<int, int>> vec = P.second, help;
    for (pair<int, int> p : vec)
      if (g_par(p.first) != g_par(p.second)) help.push_back(p);
    for (pair<int, int> p : help) ans += (merge(p.first, p.second) == false);
  }
  cout << ans;
  return 0;
}
