#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
using namespace std;
long long int ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<long long int> v;
vector<pair<long long int, long long int>> vp;
vector<vector<long long int>> vv(50, vector<long long int>(50, INF));
long long int parent(long long int num) {
  if (v[num] == num)
    return num;
  else {
    long long int res = parent(v[num]);
    v[num] = res;
    return res;
  }
}
long long int same(long long int v01, long long int v02) {
  if (parent(v01) == parent(v02))
    return 1;
  else
    return 0;
}
void unionn(long long int v01, long long int v02) {
  v[parent(v02)] = parent(v01);
}
int main() {
  cin >> n >> k;
  v.resize(n);
  for (int i = (long long int)((0)); i < (long long int)(n); i++) v[i] = i;
  vector<tuple<long long int, long long int, long long int>> vt;
  for (int i = (long long int)((0)); i < (long long int)(k); i++) {
    long long int a, b, c;
    cin >> a >> b >> c;
    vt.emplace_back(c, a, b);
  }
  sort(vt.begin(), vt.end());
  for (int i = (long long int)((0)); i < (long long int)(k); i++) {
    long long int a, b, c;
    tie(c, a, b) = vt[i];
    if (!same(a - 1, b - 1)) {
      ans++;
      unionn(a - 1, b - 1);
    }
  }
  cout << k - ans << endl;
}
