#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m];
  bool usedPath[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    usedPath[i] = false;
  }
  int cost[n + 1][n + 1];
  int mincost[n + 1];
  bool usedNode[n + 1];
  for (int i = 1; i < n + 1; i++) {
    mincost[i] = 10000;
    usedNode[i] = false;
  }
  for (int i = 0; i < m; i++) {
    cost[a[i]][b[i]] = c[i];
  }
  mincost[1] = 0;
  int cnt = 0;
  while (true) {
    int v = -1;
    for (int i = 1; i < n + 1; i++) {
      if (!usedNode[i] && (v == -1 || mincost[i] < mincost[v])) {
        v = i;
      }
    }
    if (v == -1) {
      break;
    }
    usedNode[v] = true;
    int index;
    for (int i = 1; i < n + 1; i++) {
      if (mincost[i] > cost[v][i]) {
        if (mincost[i] == 10000) {
          cnt++;
        }
        mincost[i] = cost[v][i];
      }
    }
  }
  int ans = m - cnt;
  cout << ans << endl;
  return 0;
}
