#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[105], b[105];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  int p1, p2, num;
  while (m--) {
    scanf("%d %d %d", &p1, &p2, &num);
    a[p1] += num;
    b[p2] += num;
  }
  int sum = 0;
  for (int i = 1; i < n + 1; i++) {
    if (a[i] > b[i]) sum += (a[i] - b[i]);
  }
  if (sum < 0) sum = 0;
  printf("%d", sum);
  return 0;
}
