#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
vector<pair<int, pair<int, int>>> v;
int parent[105];
void make_set(int v) { parent[v] = v; }
int find_set(int v) {
  if (v == parent[v]) return v;
  return find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) parent[b] = a;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; ++i) {
    make_set(i);
  }
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    v.push_back(make_pair(c, make_pair(a, b)));
  }
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = 0; i < int(v.size()); ++i) {
    if (find_set(v[i].second.first) != find_set(v[i].second.second)) {
      union_sets(v[i].second.first, v[i].second.second);
    } else
      cnt += 1;
  }
  cout << cnt << endl;
  return 0;
}
