#include <bits/stdc++.h>
long long ppl[101];
int main() {
  long long n, m, i;
  scanf("%lld %lld", &n, &m);
  for (i = 0; i < m; ++i) {
    long long sender, reciever, amt;
    scanf("%lld %lld %lld", &sender, &reciever, &amt);
    ppl[sender] -= amt;
    ppl[reciever] += amt;
  }
  long long total = 0;
  for (i = 0; i <= n; ++i)
    if (ppl[i] > 0) total += ppl[i];
  printf("%lld\n", total);
  return 0;
}
