#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
struct edge {
  int u, v, cost;
};
edge es[1005];
bool cmp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
template <class Abel>
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;
  UnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }
  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y, Abel w) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y), w = -w;
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }
  Abel diff(int x, int y) { return weight(y) - weight(x); }
};
vector<int> check;
int V, E;
void kruskal() {
  sort(es, es + E, cmp);
  UnionFind<int> uf(V);
  int ans = 0;
  for (int i = 0; i < (E); ++i) {
    edge e = es[i];
    if (!uf.issame(e.u, e.v)) {
      uf.merge(e.u, e.v, e.cost);
      ans += e.cost;
      check.push_back(i);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E;
  for (int i = 0; i < (E); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edge e;
    e.u = a, e.v = b, e.cost = c;
    es[i] = e;
  }
  kruskal();
  bool used[1005];
  for (int i = 0; i < (check.size()); ++i) {
    used[check[i]] = true;
  }
  int ans = 0;
  for (int i = 0; i < (E); ++i) {
    if (!used[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}
