#include <bits/stdc++.h>
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int pass[101][101][1] = {0}, x, y, z;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    pass[x][y][0] = z;
    pass[y][x][0] = z;
  }
  int count = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (pass[i][j][0] != 0) {
        count++;
      }
    }
    count--;
  }
  printf("%d\n", count);
  return 0;
}
