#include <bits/stdc++.h>
using namespace std;
template <class my>
my aabs(const my &a) {
  return (a > 0) ? a : -a;
}
long long int gcd(long long int a, long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
long long int LSOne(long long int k) { return (k & (-k)); }
class UnionFind {
 private:
  vector<int> p, ran;

 public:
  UnionFind(int N) {
    ran.assign(N, 0);
    p.assign(N, 0);
    for (int i = 0; i < N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  int unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      int x = findSet(i), y = findSet(j);
      if (ran[x] > ran[y])
        p[y] = x;
      else {
        p[x] = y;
        if (ran[x] == ran[y]) ran[y]++;
      }
    } else
      return 1;
    return 0;
  }
};
bool sortcol(const pair<int, int> &v1, const pair<int, int> &v2) {
  return v1.first < v2.first;
}
vector<pair<int, int> > ur, br, ul, bl;
vector<int> up, bel, rig, lef;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, a, b, w, val = 0;
  map<int, vector<pair<int, int> > > mop;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> w;
    mop[w].push_back(make_pair(a - 1, b - 1));
  }
  for (auto &k : mop) {
    vector<pair<int, int> > contain;
    for (auto &vec : k.second) {
      if (uf.isSameSet(vec.first, vec.second)) continue;
      contain.push_back(make_pair(vec.first, vec.second));
    }
    for (auto &vec : contain) {
      val += uf.unionSet(vec.first, vec.second);
    }
  }
  cout << val << endl;
}
