#include <bits/stdc++.h>
using namespace std;
struct edge {
  int src;
  int dst;
  int length;
  edge(int s, int d, int l) : src{s}, dst{d}, length{l} {}
  bool operator<(const edge& other) const { return length < other.length; }
};
int main() {
  int N, M;
  cin >> N >> M;
  if (N - M == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<edge> edges;
  edges.reserve(M);
  for (int i = 0; i < M; ++i) {
    int src, dst, length;
    cin >> src >> dst >> length;
    edges.emplace_back(src, dst, length);
  }
  sort(edges.begin(), edges.end());
  vector<bool> exists(N, false);
  int n = 0;
  for (const auto& edge : edges) {
    if (exists[edge.src] and exists[edge.dst]) {
      ++n;
    } else {
      exists[edge.src] = exists[edge.dst] = true;
    }
  }
  cout << n << endl;
  return 0;
}
