#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[105];
  memset(A, 0, sizeof(A));
  int n, m, ans = 0, a, b, c;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b >> c;
    A[a] -= c;
    A[b] += c;
  }
  for (int i = 1; i <= n; i++)
    if (A[i] < 0) ans += (-1) * A[i];
  cout << ans << "\n";
  return 0;
}
