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