#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9;
long int b[200];
int main() {
  long l, j, i, m, n, x, y, z;
  long long second = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y >> z;
    b[x] += z;
    b[y] -= z;
  }
  for (i = 0; i <= n; i++)
    if (b[i] > 0) second = second + b[i];
  cout << second << endl;
  return 0;
}
