#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  multimap<int, pair<int, int>> e;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    pair<int, int> p = make_pair(a, b);
    e.insert(pair<int, pair<int, int>>(c, p));
  }
  int ans = 0;
  int min = e.begin()->first;
  for (auto itr = e.begin(); itr != e.end(); ++itr) {
    if (itr->first > min)
      break;
    else
      ans++;
  }
  cout << m - ans << endl;
  return 0;
}
