#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, c, i, total = 0;
  cin >> n >> m;
  vector<int> arr(n, 0);
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    arr[--a] -= c;
    arr[--b] += c;
  }
  for (i = 0; i < n; i++) {
    if (arr[i] < 0) total -= arr[i];
  }
  cout << total << endl;
  return 0;
}
