#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
template <class T>
using V = vector<T>;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  int from, to, cost;
};
bool operator>(const edge &l, const edge &r) { return l.cost > r.cost; }
ll MinimumSpanningTree(const V<V<pair<int, int>>> &g, int n,
                       vector<pair<int, int>> &edges) {
  ll res = 0;
  vector<int> v;
  v.push_back(0);
  priority_queue<edge, vector<edge>, greater<edge>> pq;
  vector<bool> seen(n);
  seen[0] = true;
  for (pair<int, int> nv : g[0]) {
    pq.push(edge{0, nv.second, nv.first});
  }
  while (int(v.size()) != n) {
    edge e = pq.top();
    pq.pop();
    if (seen[e.to]) continue;
    v.push_back(e.to);
    edges.emplace_back(e.from, e.to);
    seen[e.to] = true;
    res += e.cost;
    for (auto nv : g[e.to]) {
      if (!seen[nv.second]) pq.push(edge{e.to, nv.second, nv.first});
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  V<V<P>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(c, b);
    g[b].emplace_back(c, a);
  }
  V<P> edges;
  int a = MinimumSpanningTree(g, n, edges);
  int ans = m - int(edges.size());
  cout << ans << '\n';
}
