#include <bits/stdc++.h>
using namespace std;
class Person {
 public:
  long long debt;
  Person() { debt = 0; }
};
int main() {
  int m, n;
  cin >> m >> n;
  vector<Person> v;
  for (int i = 0; i < m; ++i) {
    v.push_back(Person());
  }
  int from, to, money;
  while (n--) {
    cin >> from >> to >> money;
    v[from - 1].debt -= money;
    v[to - 1].debt += money;
  }
  int sol = 0;
  for (int i = 0; i < v.size(); ++i) {
    if (v[i].debt >= 0) {
      sol += v[i].debt;
    }
  }
  cout << sol << endl;
}
