#include <bits/stdc++.h>
using namespace std;
int N, M;
int cost[110][110];
int mincost[110];
bool used[110];
set<pair<int, int> > S;
const int INF = 1000000009;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    cost[a][b] = c;
    cost[b][a] = c;
  }
  for (int i = 0; i < N; i++) {
    mincost[i] = INF;
    used[i] = false;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (cost[i][j]) continue;
      cost[i][j] = INF;
    }
  }
  mincost[0] = 0;
  int res = 0;
  while (true) {
    int v = -1;
    for (int u = 0; u < N; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }
    if (v == -1) break;
    used[v] = true;
    for (int u = 0; u < N; u++) {
      if (mincost[u] > cost[v][u]) {
        mincost[u] = cost[v][u];
        if (v < u) swap(v, u);
        S.insert(pair<int, int>(v, u));
      }
    }
  }
  cout << M - S.size() << endl;
  return 0;
}
