#include <bits/stdc++.h>
using namespace std;
int N, M, A, B, C;
int d[100];
int main() {
  scanf("%d%d", &N, &M);
  for (int(i) = 0; (i) < (M); (i)++) {
    scanf("%d%d%d", &A, &B, &C);
    d[--A] += C, d[--B] -= C;
  }
  int ans = 0;
  for (int(i) = 0; (i) < (N); (i)++)
    if (d[i] > 0) ans += d[i];
  printf("%d\n", ans);
}
