#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  static const int INF = 1e5;
  scanf("%d", &n);
  scanf("%d", &m);
  vector<pair<int, pair<int, int> > > v(m);
  vector<int> cost(n, INF);
  int a, b, c, ans = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    v[i] = make_pair(c, pair<int, int>(a, b));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)(m); i++) {
    if (v[i].first <= cost[v[i].second.first] ||
        v[i].first <= cost[v[i].second.second]) {
      if (v[i].first <= cost[v[i].second.first])
        cost[v[i].second.first] = v[i].first;
      if (v[i].first <= cost[v[i].second.second])
        cost[v[i].second.second] = v[i].first;
    } else
      ans += 1;
  }
  cout << ans << endl;
  return 0;
}
