#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, a, b, c;
  cin >> n >> m;
  vector<int> v(n + 1, 0);
  while (m--) {
    cin >> a >> b >> c;
    v[a] -= c;
    v[b] += c;
  }
  int res = 0;
  for (auto &num : v)
    if (num > 0) res += num;
  cout << res << endl;
}
