#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (c[i] != 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
