import numpy as np import numpy.linalg as LA N, M = map(int, input().split()) A = np.zeros((N, N), dtype=int) for i in range(0, M): a, b, c = map(int, input().split()) A[a - 1][b - 1] = c A[b - 1][a - 1] = c for i in range(0, N): A[i][i] = -sum(A[i]) eigenvalues, _ = LA.eig(A) ans = 0 for eigenvalues in eigenvalues: if abs(eigenvalues) < 1e-9: ans += 1 print(ans)