#include <bits/stdc++.h>
using namespace std;
int z[100];
int main(int argc, char* argv[]) {
  unsigned int n, m;
  cin >> n >> m;
  for (unsigned int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    z[a - 1] -= c;
    z[b - 1] += c;
  }
  int r = 0;
  for (unsigned int i = 0; i < n; ++i) {
    if (z[i] > 0) r += z[i];
  }
  cout << r << endl;
  return 0;
}
