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