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