#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7, MAXN = 100005;
long long n, m, x, y, c, res, a[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> c;
    a[x] -= c;
    a[y] += c;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] < 0) res -= a[i];
  cout << res;
  return 0;
}
