#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int fa[maxn];
int fd(int x) { return x == fa[x] ? fa[x] : fa[x] = fd(fa[x]); }
class rev {
 public:
  int u;
  int v;
  int w;
  rev(int uu = 0, int vv = 0, int ww = 0) {
    u = uu;
    v = vv;
    w = ww;
  }
};
vector<rev> edge;
int n, m;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) fa[i] = i;
  for (int i = (1); i <= (m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(rev(u, v, w));
  }
  sort((edge).begin(), (edge).end(),
       [](const rev& a, const rev& b) { return a.w < b.w; });
  int l = 0;
  int ans = 0;
  while (l < m) {
    int r = l;
    while (r < m && edge[r].w == edge[l].w) r++;
    int good = 0;
    for (int i = (l); i < (r); ++i) {
      auto& e = edge[i];
      int u = e.u;
      int v = e.v;
      if (fd(u) != fd(v)) good++;
    }
    int nd = 0;
    for (int i = (l); i < (r); ++i) {
      auto& e = edge[i];
      int u = e.u;
      int v = e.v;
      u = fd(u), v = fd(v);
      if (u == v) continue;
      fa[u] = v, nd++;
    }
    ans += (good - nd), l = r;
  }
  cout << ans << endl;
  return 0;
}
