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