#include <bits/stdc++.h>
using namespace std;
int main2() {
  int n, m;
  n = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  m = ({
    int t;
    scanf("%d", &t);
    t;
  });
  int owe[n + 2];
  memset(owe, 0, sizeof(owe));
  for (int i = 0, _n = m; i < _n; i++) {
    int a, b, c;
    a = ({
      int t;
      scanf("%d", &t);
      t;
    }),
    b = ({
      int t;
      scanf("%d", &t);
      t;
    }),
    c = ({
      int t;
      scanf("%d", &t);
      t;
    });
    owe[a] += c;
    owe[b] -= c;
  }
  int cnt = 0;
  for (int i = 1; i < n + 1; i++) {
    cnt += max(owe[i], 0);
  }
  printf("%d\n", cnt);
  return 0;
}
int main() { main2(); }
