#include <bits/stdc++.h>
using namespace std;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
int N, M;
vector<vector<int> > es;
vector<vector<bool> > used;
int solve() {
  for (int i = 0; i < (N); i++) {
    pair<int, int> p;
    int cost_max = INF;
    for (int j = 0; j < (N); j++) {
      if (i == j) continue;
      if (es[i][j] < cost_max) {
        p = make_pair(i, j);
        cost_max = es[i][j];
      }
    }
    used[p.first][p.second] = true;
  }
  int ans = 0;
  for (int i = 0; i < (used.size()); i++) {
    for (int j = 0; j < (used[i].size()); j++) {
      if (!used[i][j]) {
        ans++;
      }
    }
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  es.resize(N, vector<int>(N));
  used.resize(N, vector<bool>(N));
  for (int i = 0; i < (M); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    es[a - 1][b - 1] = c;
    es[b - 1][a - 1] = c;
  }
  cout << solve() << endl;
  return 0;
}
