#include <bits/stdc++.h>
using namespace std;
int totalSum = 0;
map<pair<int, int>, bool> visited;
int main() {
  int n, m;
  while (cin >> n >> m) {
    totalSum = 0;
    visited.clear();
    int a, b, c;
    map<int, int> OWES, HAVE;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      HAVE[a] -= c;
      HAVE[b] += c;
    }
    for (int i = 1; i < n + 1; i++) {
      if (HAVE[i] < 0) totalSum += HAVE[i];
    }
    cout << abs(totalSum) << endl;
  }
  return 0;
}
