#include <bits/stdc++.h>
using namespace std;
const int M = 100000;
int main(void) {
  long long n, m, i, a, b, c;
  long long get[M] = {
      0,
  };
  long long give[M] = {
      0,
  };
  long long debt = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    give[a] += c;
    get[b] += c;
  }
  for (i = 1; i <= n; i++) {
    if (get[i] < give[i]) debt += give[i] - get[i];
  }
  cout << debt << endl;
  return 0;
}
