#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int MXN = 200001;
int link[MXN];
int size[MXN];
bool vis[MXN] = {false};
vector<int> ad[MXN];
int find(int a) {
  if (a != link[a]) return link[a] = find(link[a]);
  return a;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (size[a] > size[b]) swap(a, b);
  link[a] = b;
  size[b] += size[a];
}
int c = 0;
int main() {
  cin >> n >> m;
  vector<pair<long long, pair<int, int> > > kk;
  while (m--) {
    long long a, b, w;
    cin >> a >> b >> w;
    kk.push_back(make_pair(w, make_pair(a, b)));
    ad[a].push_back(b);
    ad[b].push_back(a);
  }
  long long cost = 0;
  vector<pair<int, int> > ans;
  sort(kk.begin(), kk.end());
  for (int i = 1; i <= n; i++) size[i] = 1;
  for (int i = 1; i <= n; i++) link[i] = i;
  for (int i = 0; i < kk.size(); i++) {
    int j = i;
    while (j < kk.size() && kk[i].first == kk[j].first) j++;
    int tot = j - i;
    for (int l = i; l < j; l++)
      tot -= (find(kk[l].second.first) == find(kk[l].second.second));
    for (int l = i; l < j; l++) {
      if (find(kk[l].second.first) != find(kk[l].second.second)) {
        unite(kk[l].second.first, kk[l].second.second);
        tot--;
      }
    }
    cost += tot;
    i = j - 1;
  }
  cout << cost;
  return 0;
}
