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