#include <bits/stdc++.h>
using namespace std;
int in[111] = {0}, out[111] = {0};
int main(void) {
  int n, m, a, b, c, i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    in[b] += c;
    out[a] += c;
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    if (in[i] >= out[i])
      continue;
    else
      ans += out[i] - in[i];
  }
  printf("%d\n", ans);
  return 0;
}
