#include <bits/stdc++.h>
using namespace std;
int dise[110], nise[110], g[110][110];
int main() {
  int n, m, x, y, z;
  while (cin >> n >> m) {
    memset(dise, 0, sizeof(dise));
    memset(nise, 0, sizeof(nise));
    memset(g, 0, sizeof(g));
    for (int i = 0; i < m; i++) {
      cin >> x >> y >> z;
      g[x][y] = z;
      dise[x] += z;
      nise[y] += z;
    }
    long long int tot = 0;
    for (int i = 1; i <= n; i++)
      tot += (nise[i] > dise[i] ? nise[i] - dise[i] : 0);
    cout << tot << endl;
  }
  return 0;
}
