#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
struct edge {
  int from, to, cost;
};
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int V, E;
vector<edge> es;
int par[100];
int ran[100];
void init(int N) {
  for (int i = 0; i < N; i++) {
    par[i] = i;
    ran[i] = 0;
  }
}
int find(int X) {
  if (par[X] == X) {
    return X;
  } else {
    return par[X] = find(par[X]);
  }
}
void unite(int X, int Y) {
  X = find(X);
  Y = find(Y);
  if (X == Y) {
    return;
  }
  if (ran[X] < ran[Y]) {
    par[X] = Y;
  } else {
    par[Y] = X;
    if (ran[X] == ran[Y]) {
      ran[X]++;
    }
  }
}
bool same(int X, int Y) { return find(X) == find(Y); }
int kruskal() {
  sort(es.begin(), es.end(), comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.from, e.to)) {
      unite(e.from, e.to);
      res++;
    }
  }
  return res;
}
int main() {
  cin >> V >> E;
  int S = 0;
  for (int i = 0; i < E; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    es.push_back({A, B, C});
  }
  cout << E - kruskal() << endl;
  return 0;
}
