#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> debts(n);
  fill(debts.begin(), debts.end(), 0);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    debts[a - 1] -= c;
    debts[b - 1] += c;
  }
  int answer = 0;
  for (int i = 0; i < n; i++) {
    if (debts[i] > 0) {
      answer += debts[i];
    }
  }
  cout << answer << "\n";
}
