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