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