#include <bits/stdc++.h>
using namespace std;
int in[1000], out[1000];
int main() {
  int n, m;
  while (cin >> n >> m) {
    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));
    for (int i = 0; i < m; i++) {
      int x, y, v;
      cin >> x >> y >> v;
      out[x] += v;
      in[y] += v;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (out[i] - in[i] > 0) ans += (out[i] - in[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
