#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct dsu {
  int forests = 0, parent[N], groupsize[N];
  void add(int x) {
    parent[x] = x;
    groupsize[x] = 1;
    forests++;
  }
  int findset(int node) {
    if (parent[node] == node) return node;
    return parent[node] = findset(parent[node]);
  }
  bool issameset(int x, int y) { return findset(x) == findset(y); }
  void link(int i, int j) {
    int x = findset(i), y = findset(j);
    if (x == y) return;
    if (groupsize[x] < groupsize[y]) swap(x, y);
    groupsize[x] += groupsize[y];
    parent[y] = x;
    forests--;
  }
};
map<long long, int> mp;
map<int, vector<pair<int, int>>> e;
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  dsu mst;
  for (int i = 1; i <= n; ++i) mst.add(i);
  for (int i = 1; i <= m; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    e[c].push_back({x, y});
  }
  long long sum = 0, mx = 0;
  for (auto u : e) {
    int add = 0;
    for (auto uu : u.second) {
      if (!mst.issameset(uu.first, uu.second)) {
        add++;
      }
    }
    for (auto uu : u.second) {
      if (!mst.issameset(uu.first, uu.second)) {
        add--;
        mst.link(uu.first, uu.second);
      }
    }
    sum += add;
  }
  cout << sum << "\n";
  return 0;
}
