#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b, c, sum = 0;
  cin >> n >> m;
  map<int, int> debt;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    debt[a] -= c;
    debt[b] += c;
  }
  for (int i = 1; i <= n; i++) {
    if (debt[i] > 0) {
      sum += debt[i];
    }
  }
  cout << sum;
  return 0;
}
