#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int parent[N];
int sz[N];
void make_set(int v) {
  parent[v] = v;
  sz[v] = 1;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    parent[b] = a;
    sz[a] += sz[b];
  }
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  };
  int n, m;
  cin >> n >> m;
  map<int, vector<pair<int, int>>> edge_map;
  vector<pair<int, pair<int, int>>> edges;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edges.push_back({w, {u, v}});
    edge_map[w].push_back({u, v});
  }
  for (int i = 1; i <= n; i++) make_set(i);
  int ans = 0;
  for (auto item : edge_map) {
    vector<pair<int, int>> edges = item.second;
    vector<pair<int, int>> useful;
    for (pair<int, int> edge : edges) {
      int u = edge.first, v = edge.second;
      if (find_set(u) != find_set(v)) useful.push_back({u, v});
    }
    int merges = 0;
    for (pair<int, int> edge : useful) {
      int u = edge.first, v = edge.second;
      if (find_set(u) != find_set(v)) {
        merges++;
        union_sets(u, v);
      }
    }
    ans += (useful.size() - merges);
  }
  cout << ans << endl;
}
