#include <bits/stdc++.h>
using namespace std;
template <typename T>
T POW(T b, T p) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b);
    b = (b * b);
    p >>= 1;
  }
  return r;
}
template <typename T>
T BigMod(T b, T p, T m) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b) % m;
    b = (b * b) % m;
    p >>= 1;
  }
  return r;
}
int main() {
  int n, m, u, v, cost[60010];
  while (cin >> n >> m) {
    int minimum = 2147483647;
    for (int i = 0; i < (m); i++) {
      cin >> v >> u >> cost[i];
      minimum = min(minimum, cost[i]);
    }
    int cnt = 0;
    for (int i = 0; i < (m); i++) {
      if (cost[i] != minimum) cnt++;
    }
    cout << cnt << endl;
  }
}
