#include <bits/stdc++.h>
using namespace std;
int incoming[110];
int outgoing[110];
int main(int argc, const char* argv[]) {
  int n, m;
  cin >> n >> m;
  int a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    incoming[b] += c;
    outgoing[a] += c;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (outgoing[i] - incoming[i] > 0) ans += outgoing[i] - incoming[i];
  }
  cout << ans;
}
