#include <bits/stdc++.h>
using namespace std;
int cost[100][100];
int mincost[100];
bool used[100];
int V;
long long ans;
int prim() {
  for (int i = (int)0; i < (int)V; ++i) {
    mincost[i] = 1000000000;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;
  while (true) {
    int v = -1;
    for (int u = (int)0; u < (int)V; ++u) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }
    if (v == -1) break;
    used[v] = true;
    res += mincost[v];
    ans++;
    for (int u = (int)0; u < (int)V; ++u) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}
int main(void) {
  int m;
  cin >> V >> m;
  for (int i = (int)0; i < (int)V; ++i)
    for (int j = (int)0; j < (int)V; ++j) {
      cost[i][j] = 1000000000;
    }
  for (int i = (int)0; i < (int)m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    cost[a - 1][b - 1] = c;
    cost[b - 1][a - 1] = c;
  }
  prim();
  cout << m - ans + 1 << endl;
  return 0;
}
