#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000009;
const long long MAX = 101;
long long n, m;
struct Edge {
  long long src;
  long long dst;
  long long wei;
  Edge(long long s = 0, long long d = 0, long long w = 0)
      : src(s), dst(d), wei(w) {}
};
using Graph = vector<vector<Edge>>;
long long par[100005];
long long rnk[100005];
long long root(long long x) { return par[x] == x ? x : par[x] = root(par[x]); }
void unite(long long a, long long b) { par[root(a)] = root(b); }
bool f(const Edge& a, const Edge& b) { return a.wei < b.wei; }
long long Kruskal(Graph& g) {
  vector<Edge> es;
  for (long long i = 0; i < g.size(); i++) {
    for (long long j = 0; j < g[i].size(); j++) {
      es.push_back(g[i][j]);
    }
  }
  sort(es.begin(), es.end(), f);
  for (long long i = 0; i < g.size(); i++) par[i] = i;
  long long sum = 0;
  long long ans = 0;
  for (long long i = 0; i < es.size(); i++) {
    if (root(es[i].src) != root(es[i].dst)) {
      sum += es[i].wei;
      unite(es[i].src, es[i].dst);
      ans++;
    }
  }
  return ans;
}
signed main() {
  cin >> n >> m;
  Graph g(n);
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(a, b, c);
    g[b].emplace_back(b, a, c);
  }
  long long ans = Kruskal(g);
  cout << m - ans << endl;
  return 0;
}
