#include <bits/stdc++.h>
using namespace std;
long long has[100];
long long owe[100][100];
int n, m;
int main() {
  cin >> n >> m;
  memset(owe, 0, sizeof owe);
  long long a, b, c;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> c;
    owe[a - 1][b - 1] = c;
  }
  memset(has, 0, sizeof has);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      has[i] += owe[i][j] - owe[j][i];
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += max(0LL, has[i]);
  cout << ans << endl;
  return 0;
}
