#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000000;
template <class T>
T read(T &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return x;
}
int p[200005];
int f(int x) { return p[x] = (x == p[x] ? x : f(p[x])); }
int n;
int m;
struct edge {
  int u, v, w;
  bool operator<(edge b) const { return w < b.w; }
};
vector<edge> v;
pair<int, int> make(int a, int b) { return make_pair(min(a, b), max(a, b)); }
pair<int, int> ok[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) p[i] = i;
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    v.push_back({x, y, z});
  }
  sort(v.begin(), v.end());
  int j = 0;
  int ans = 0;
  for (int i = 0; i < v.size(); i = j + 1) {
    while (j + 1 < v.size() && v[j + 1].w <= v[i].w) j++;
    for (int k = i; k <= j; ++k) ok[k] = make(f(v[k].u), f(v[k].v));
    for (int k = i; k <= j; ++k) {
      if (f(v[k].u) == f(v[k].v) && ok[k].first != ok[k].second)
        ans++;
      else if (f(v[k].u) != f(v[k].v)) {
        p[f(v[k].u)] = f(v[k].v);
      }
    }
  }
  cout << ans << endl;
}
