#include <bits/stdc++.h>
using namespace std;
long long kq = 0;
int n, a[101], u, c, v, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    a[u] -= c;
    a[v] += c;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] > 0) kq += a[i];
  cout << kq;
}
