#include <bits/stdc++.h>
using namespace std;
int inm[101], oum[101], mo[101];
vector<int> gr[101], w[101];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans = 0;
  for (int a, b, c, i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    inm[b] += c;
    oum[a] -= c;
  }
  for (int i = 1; i <= n; i++) {
    mo[i] = inm[i] + oum[i];
    if (mo[i] >= 0) ans += mo[i];
  }
  printf("%d\n", ans);
  return 0;
}
