#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int par[N];
struct T {
  int u, v, w;
};
vector<T> V[N], tmp, G;
bool cmp(T a, T b) { return a.w < b.w; }
int find(int x) {
  int p = x, c;
  while (par[p] != p) p = par[p];
  while (par[x] != x) c = par[x], par[x] = p, x = c;
  return p;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    G.push_back({u, v, w});
  }
  sort(G.begin(), G.end(), cmp);
  int L = -1, ans = 0;
  for (auto k : G) {
    if (k.w != L) {
      L = k.w;
      for (auto g : tmp) {
        int a = find(g.u), b = find(g.v);
        if (a != b) par[b] = a;
      }
      tmp.clear();
    }
    int a = find(k.u), b = find(k.v);
    if (a != b) ans++, tmp.push_back(k);
  }
  cout << ans - (n - 1) << '\n';
}
