#include <bits/stdc++.h>
using namespace std;
template <typename T>
void DEBUG(T e) {
  if (true == false) return;
  std::cout << e << std::endl;
}
template <typename T>
void DEBUG(const std::vector<T> &v) {
  if (true == false) return;
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T> > &vv) {
  if (true == false) return;
  for (const auto &v : vv) {
    DEBUG(v);
  }
}
template <class T, class X>
void DEBUG(X d, T e) {
  if (true == false) return;
  std::cout << d << " ";
  DEBUG(e);
};
template <class T>
void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    exit(0);
  }
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
struct UnionFind {
  vector<long long> data;
  UnionFind(long long sz) { data.assign(sz, -1); }
  bool unite(long long x, long long y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  long long find(long long k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  long long size(long long k) { return (-data[find(k)]); }
};
template <typename T>
struct edge {
  long long src, to;
  T cost;
  edge(long long to, T cost) : src(-1), to(to), cost(cost) {}
  edge(long long src, long long to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const long long &x) {
    to = x;
    return *this;
  }
  operator long long() const { return to; }
};
template <typename T>
using Edges = vector<edge<T> >;
template <typename T>
using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<long long> >;
template <typename T>
using Matrix = vector<vector<T> >;
template <typename T>
T kruskal(Edges<T> &edges, long long V) {
  sort(begin(edges), end(edges),
       [](const edge<T> &a, const edge<T> &b) { return (a.cost < b.cost); });
  long long NUM = 0;
  UnionFind tree(V);
  T ret = 0;
  for (auto &e : edges) {
    if (tree.unite(e.src, e.to)) {
      ret += e.cost;
      NUM++;
    }
  }
  return (NUM);
}
void solve(void) {
  long long N, M;
  cin >> N >> M;
  Edges<long long> E;
  for (long long i = 0; i < M; i++) {
    long long A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    edge<long long> e(A, B, C);
    edge<long long> e_r(B, A, C);
    E.push_back(e);
    E.push_back(e_r);
  }
  cout << M - (long long)kruskal(E, N) << endl;
  return;
}
int32_t main(int32_t argc, const char *argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  return 0;
}
