#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vvi vabc;
bool func(vi v) {
  for (int(i)(0); (i) < (vabc.size()); ++(i)) {
    if (vabc[i][2] < v[2] && (vabc[i][0] == v[0] || vabc[i][1] == v[0])) {
      int ai = vabc[i][0] == v[0] ? 0 : 1;
      int bi = ai ? 0 : 1;
      if (vabc[i][bi] == v[1] || func({vabc[i][bi], v[1], v[2] - vabc[i][2]})) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int(i)(0); (i) < (M); ++(i)) {
    int a, b, c;
    cin >> a >> b >> c;
    vabc.push_back({a, b, c});
  }
  int ans(0);
  for (int(i)(0); (i) < (vabc.size()); ++(i)) {
    if (func(vabc[i])) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
