#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[100000];
int a[10005];
int main() {
  int i, j, k, n, m, x, y, z, q = 0, r;
  cin >> n >> m;
  int b[n];
  for (i = 0; i < m; i++) {
    cin >> x >> y >> z;
    a[x] = a[x] - z;
    a[y] = a[y] + z;
  }
  for (i = 0; i <= n; i++) {
    q = q + max(0, a[i]);
  }
  cout << q << endl;
}
