#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
  int from;
  int to;
  int cost;
};
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) { return -par[root(x)]; }
};
int kruskal(vector<edge> &graph, int V) {
  sort((graph).begin(), (graph).end(),
       [](const edge &a, const edge &b) { return a.cost < b.cost; });
  UnionFind uf(V);
  int res = 0;
  for (int v = 0; v < (int)graph.size(); v++) {
    edge e = graph[v];
    if (!uf.issame(e.from, e.to)) {
      uf.merge(e.from, e.to);
      res++;
    }
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<edge> graph;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    graph.push_back(edge{a, b, c});
    graph.push_back(edge{b, a, c});
  }
  int ans = kruskal(graph, n);
  cout << m - ans << endl;
}
