#include <bits/stdc++.h>
using namespace std;
const int M = 128;
int num[M];
int main() {
  int n, m, a, b, c;
  while (~scanf("%d%d", &n, &m)) {
    memset(num, 0, sizeof(num));
    while (m--) {
      scanf("%d%d%d", &a, &b, &c);
      num[a] -= c;
      num[b] += c;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (num[i] > 0) ans += num[i];
    }
    printf("%d\n", ans);
  }
  return 0;
}
