#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, d;
int dat[3002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> d;
  for (int i = 1; i <= d; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    dat[a] -= c;
    dat[b] += c;
  }
  int sol = 0;
  for (int i = 1; i <= n; ++i)
    if (dat[i] > 0) sol += dat[i];
  cout << sol;
  return 0;
}
