#include <bits/stdc++.h>
using namespace std;
int vi[1010];
int n;
int main() {
  int m;
  int a, b, c;
  while (cin >> n >> m) {
    int i;
    memset(vi, 0, sizeof(vi));
    for (i = 0; i < m; i++) {
      cin >> a >> b >> c;
      vi[a] -= c;
      vi[b] += c;
    }
    int sum = 0;
    for (i = 1; i <= n; i++)
      if (vi[i] > 0) {
        sum += vi[i];
      }
    cout << sum << endl;
  }
  return 0;
}
