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