#include <bits/stdc++.h>
using namespace std;
int ppl[1000] = {0};
int main() {
  int t, m, n, a, b, c, i;
  long long sm = 0;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b >> c;
    ppl[a] -= c;
    ppl[b] += c;
  }
  for (i = 1; i <= n; i++)
    if (ppl[i] > 0) sm += ppl[i];
  cout << sm << endl;
}
