#include <bits/stdc++.h>
using namespace std;
int main() {
  int p, n, x, y, s;
  cin >> p >> n;
  int *giv = new int[p];
  int *tak = new int[p];
  for (int i = 0; i < p; i++) {
    giv[i] = tak[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> s;
    giv[x - 1] += s;
    tak[y - 1] += s;
  }
  s = 0;
  for (int a = 0; a < p; a++) {
    if (giv[a] >= tak[a]) s += giv[a] - tak[a];
  }
  cout << s;
  return 0;
}
