#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2;
const int maxn = 1e6 + 100;
int n, m, an[maxn];
void fill() {
  for (int i = 0; i < n + 1; i++) {
    an[i] = i;
  }
}
int findc(int x) {
  while (x != an[x]) x = an[x] = an[an[x]];
  return x;
}
void une(int a, int b) { an[findc(a)] = findc(b); }
bool same(int a, int b) { return findc(a) == findc(b); }
vector<pair<int, pair<int, int> > > e, mst, fora;
int idx = 0, j = 0;
void first(int x) {
  while (idx < (int)mst.size() && mst[idx].first < x) {
    une(mst[idx].second.first, mst[idx].second.second);
    idx++;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  fill();
  if (m <= n - 1) {
    return printf("0\n"), 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    e.push_back({c, {a, b}});
  }
  sort(e.begin(), e.end());
  for (int i = 0; i < m; i++) {
    int x = e[i].second.first, y = e[i].second.second;
    if (same(x, y)) {
      fora.push_back(e[i]);
    } else {
      mst.push_back(e[i]);
      une(x, y);
    }
  }
  int mst_size = (int)mst.size(), ans = 0, n = (int)fora.size();
  fill();
  while (idx < mst_size && j < n) {
    int a = fora[j].second.first;
    int b = fora[j].second.second;
    int c = fora[j].first;
    first(c);
    if (same(a, b) == 0) {
      ++ans;
    }
    j++;
  }
  cout << ans << '\n';
  return 0;
}
