// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100, M = 1000;

struct E {
	int i, j, w;
} ee[M];

int ds[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	int n, m; cin >> n >> m;
	for (int h = 0; h < m; h++) {
		int i, j, w; cin >> i >> j >> w, i--, j--;
		auto &e = ee[h];
		e.i = i;
		e.j = j;
		e.w = w;
	}
	sort(ee, ee + m, [] (auto &e, auto &f) { return e.w < f.w; });
	fill(ds, ds + n, -1);
	int ans = 0;
	for (int h1 = 0, h2; h1 < m; h1 = h2) {
		int w = ee[h1].w;
		h2 = h1 + 1;
		while (h2 < m && ee[h2].w == w)
			h2++;
		for (int h = h1; h < h2; h++) {
			auto &e = ee[h];
			if (find(e.i) == find(e.j))
				ans++;
		}
		for (int h = h1; h < h2; h++) {
			auto &e = ee[h];
			join(e.i, e.j);
		}
	}
	cout << ans << '\n';
	return 0;
}
