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