#include <bits/stdc++.h>
using namespace std;
const int M = 100010;
int INF = 1000000007;
using ll = long long;
int n, m;
int a[110], b[110], c[110];
bool f[110] = {};
int check(int i, int j) {
  int ans = INF;
  for (int k = 1; k < m + 1; k++) {
    if ((a[k] == i && b[k] == j) || (a[k] == j && b[k] == i)) {
      ans = 1;
    }
  }
  if (ans == INF)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i < m + 1; i++) cin >> a[i] >> b[i] >> c[i];
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      if (check(i, j)) {
        ans += check(i, j);
        break;
      }
    }
  }
  cout << m - ans << endl;
}
