#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265359;
long long const oo = 1e17;
void BEGIN() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
int dept[101];
void solve() {
  int n, m, a, b, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    dept[a - 1] -= c;
    dept[b - 1] += c;
  }
  int ans = 0;
  for (int i = 0; i < 101; i++) {
    if (dept[i] > 0) ans += dept[i];
  }
  cout << ans << endl;
}
int main() {
  BEGIN();
  int t = 1;
  while (t--) solve();
}
