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