#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, c;
};
bool csort(const edge& e1, const edge& e2) { return e1.c < e2.c; }
int par[101];
int trank[101];
int find(int x) {
  if (par[x] == x) return x;
  return find(par[x]);
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (trank[x] < trank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (trank[x] == trank[y]) {
      trank[x]++;
    }
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  for (int i = 0; i < (int)(101); i++) {
    par[i] = i;
    trank[i] = 0;
  }
  int N, M;
  cin >> N >> M;
  vector<edge> es;
  for (int i = 0; i < (int)(M); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge e = {a, b, c};
    es.push_back(e);
  }
  sort((es).begin(), (es).end(), csort);
  int cnt = 0;
  for (int i = 0; i < (int)(M); i++) {
    if (same(es[i].a, es[i].b)) continue;
    unite(es[i].a, es[i].b);
    cnt++;
  }
  cout << M - cnt << endl;
  return 0;
}
