#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, cost;
};
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
class UnionFind {
 private:
  int par[100];
  int rank[100];
  int s[100];

 public:
  void init(int n);
  int find(int x);
  void unite(int x, int y);
  bool same(int x, int y);
};
void UnionFind::init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rank[i] = 0;
    s[i] = 1;
  }
}
int UnionFind::find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void UnionFind::unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rank[x] < rank[y]) {
    par[x] = y;
    s[y] = s[x] + s[y];
  } else {
    par[y] = x;
    s[x] = s[x] + s[y];
    if (rank[x] == rank[y]) rank[x]++;
  }
}
bool UnionFind::same(int x, int y) { return find(x) == find(y); }
edge es[1000];
int V, E;
int main(void) {
  cin >> V >> E;
  for (int i = (int)0; i < (int)E; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    es[i] = (edge){(a - 1), (b - 1), c};
  }
  sort(es, es + E, comp);
  UnionFind a;
  a.init(V);
  long long ans = 0;
  for (int i = (int)0; i < (int)E; ++i) {
    edge e = es[i];
    if (!a.same(e.u, e.v)) {
      a.unite(e.u, e.v);
    } else {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
