#include <bits/stdc++.h>
using namespace std;
int par[200005], n;
long long ans;
map<long long, long long> comp, use;
map<int, vector<pair<int, int> > > mm;
vector<pair<long long, pair<int, int> > > Q;
void intialize() {
  for (int i = 1; i <= n; i++) par[i] = i;
}
int parent(int x) {
  if (par[x] != x) {
    par[x] = parent(par[x]);
  }
  return par[x];
}
void unions(int x, int y) {
  int p = parent(x);
  int q = parent(y);
  par[p] = q;
}
void findans() {
  for (auto it : mm) {
    stack<pair<long long, pair<int, int> > > st;
    for (int i = 0; i < (it).second.size(); i++) {
      if (parent((it).second[i].first) != parent(it.second[i].second)) {
        st.push(make_pair(it.first,
                          make_pair(it.second[i].first, it.second[i].second)));
      }
    }
    comp[it.first] = st.size();
    while (st.size()) {
      pair<long long, pair<int, int> > p = st.top();
      st.pop();
      int x = p.second.first;
      int y = p.second.second;
      if (parent(x) != parent(y)) {
        unions(x, y);
        use[p.first]++;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int m, x, y;
  long long w;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> w;
    mm[w].push_back(make_pair(x, y));
  }
  intialize();
  findans();
  for (auto it : comp) {
    ans += (it.second - use[it.first]);
  }
  cout << ans;
  return 0;
}
