#include <bits/stdc++.h>
using namespace std;
int par[100001];
struct edge {
  int cost, from, to;
};
void init(int x) {
  for (int i = 0; i < x; i++) par[i] = i;
}
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
void unit(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  else
    par[y] = x;
}
int s, t, w, v, e, ans;
bool check[100001];
vector<edge> edges;
int main() {
  cin >> v >> e;
  for (int i = 0; i < e; i++) {
    cin >> s >> t >> w;
    edges.push_back(edge{w, s, t});
  }
  sort(edges.begin(), edges.end(),
       [](edge x, edge y) { return x.cost < y.cost; });
  init(v);
  for (int i = 0; i < e; i++) {
    int x = edges[i].from, y = edges[i].to, z = edges[i].cost;
    if (!same(x, y)) {
      check[i] = 1;
      unit(x, y);
    }
  }
  for (int i = 0; i < e; i++) {
    if (!check[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}
