#include <bits/stdc++.h>
using namespace std;
struct reb {
  long long int end1;
  long long int t;
};
vector<reb> a[1000], b[1000];
long long int debt[1000];
int main() {
  long long int n, m, br = 0, i, j, x, y, t;
  reb p;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y >> t;
    p.t = t;
    p.end1 = y - 1;
    a[x - 1].push_back(p);
    p.end1 = x - 1;
    b[y - 1].push_back(p);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < a[i].size(); j++) {
      debt[i] -= a[i][j].t;
    }
    for (j = 0; j < b[i].size(); j++) {
      debt[i] += b[i][j].t;
    }
    if (debt[i] > 0) br += debt[i];
  }
  cout << br;
  cout << endl;
}
