#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using pii = pair<long long, long long>;
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i) is >> *i;
  return is;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
void PSUM(T &c) {
  partial_sum(begin(c), end(c), begin(c));
}
template <class T>
using heap = priority_queue<T, vector<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
struct union_find {
  vector<long long> data;
  union_find(long long size) : data(size, -1) {}
  void unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }
  long long size(long long x) { return -data[root(x)]; }
};
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<vi> E(m);
  map<long long, vi> mp;
  for (long long i = 0, ilen = (long long)(m); i < ilen; ++i) {
    long long a, b, w;
    cin >> a >> b >> w;
    a--, b--;
    E[i] = {w, a, b};
    mp[w].push_back(i);
  }
  union_find uf(n);
  long long ans = 0;
  for (auto &&v : mp) {
    vector<long long> e;
    for (auto &&idx : v.second) {
      long long a = E[idx][1], b = E[idx][2];
      if (uf.same(a, b)) {
        continue;
      }
      e.push_back(idx);
    }
    for (auto &&idx : e) {
      long long a = E[idx][1], b = E[idx][2];
      if (uf.same(a, b)) {
        ans++;
      } else {
        uf.unite(a, b);
      }
    }
  }
  cout << ans << endl;
  return (0 ^ 0 ^ 0);
}
