#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
int ar[1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, debt, i, a, b, ans = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> debt;
    ar[a] += debt;
    ar[b] -= debt;
  }
  for (i = 0; i <= n; i++) {
    ans += (ar[i] > 0) ? ar[i] : 0;
  }
  cout << ans << '\n';
}
