#include <bits/stdc++.h>
using namespace std;
int ara[200];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, m, i, j, k, temp, ans = 0, a, b, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    ara[a] -= c;
    ara[b] += c;
  }
  for (int i = 0; i < n + 2; i++) {
    if (ara[i] > 0) ans += ara[i];
  }
  cout << ans;
}
