#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for (int i = 0; i < sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for (int i = 0; i < sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if (par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  void Union(int a, int b) {
    a = Find(a), b = Find(b);
    if (a == b) return;
    if (hei[a] < hei[b])
      par[a] = b, sz[b] += sz[a];
    else
      par[b] = a, sz[a] += sz[b];
    if (hei[a] == hei[b]) ++hei[a];
  }
  int Size(const int& n) { return sz[Find(n)]; }
};
long long ncase = 1;
long long N, M, a, b, c;
string str;
map<int, vector<pair<int, int> > > Edge;
vector<pair<int, int> > vec;
void pre() { return; }
void init() {
  N = getint();
  M = getint();
  for (int i = 0; i < M; ++i) {
    a = getint() - 1;
    b = getint() - 1;
    c = getint();
    Edge[c].emplace_back(a, b);
  }
}
void sol() {
  int res = 0;
  UF uf(N);
  for (auto& e : Edge) {
    vec.clear();
    for (auto i : e.second)
      if (uf.Find(i.first) != uf.Find(i.second)) vec.push_back(i);
    for (auto i : vec) {
      a = uf.Find(i.first);
      b = uf.Find(i.second);
      if (a == b)
        ++res;
      else
        uf.Union(a, b);
    }
  }
  cout << res << endl;
  return;
}
int main() {
  pre();
  while (ncase--) {
    init();
    sol();
  }
}
