#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, k, i, m, n, sum;
  int a[105];
  cin >> n >> m;
  memset(a, 0, sizeof(a));
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> k;
    a[x] += -k;
    a[y] += k;
  }
  sum = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] < 0) {
      sum += a[i];
    }
  }
  cout << -sum << endl;
}
