#include <bits/stdc++.h>
using namespace std;
void IOS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return;
  }
  vector<long long> v(n + 1, 0);
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    v[a] -= c;
    v[b] += c;
  }
  long long sum = 0;
  for (long long i = 0; i < n + 1; i++)
    if (v[i] < 0) sum += -v[i];
  cout << sum;
  cout << endl;
}
int32_t main() {
  IOS();
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
