#include <bits/stdc++.h>
using namespace std;
bool used[1010];
typedef pair<int, int> pii;
vector<pii> G[1010];
long long cnt = 1;
int prim_1() {
  priority_queue<pii> que;
  fill(used, used + 1010, false);
  que.push(pii(0, 0));
  int ret = 0;
  while (!que.empty()) {
    int v = que.top().second;
    int cst = (-1) * (que.top().first);
    que.pop();
    if (used[v]) continue;
    used[v] = true;
    cnt++;
    ret += cst;
    for (int i = 0; i < (int)G[v].size(); i++)
      que.push(pii((G[v][i].first) * (-1), (G[v][i].second)));
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int M;
  int N;
  cin >> N >> M;
  for (long long(i) = (0); (i) < (M); (i)++) {
    int s, t, c;
    cin >> s >> t >> c;
    G[s].push_back(pii(c, t));
    G[t].push_back(pii(c, s));
  }
  prim_1();
  long long ans;
  ans = M - cnt;
  cout << ans << endl;
  return 0;
}
