#include <bits/stdc++.h>
using namespace std;
int people[105];
int main() {
  int a, b, c;
  memset(people, 0, sizeof(people));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    people[a] -= c;
    people[b] += c;
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    if (people[i] > 0) sum += people[i];
  printf("%I64d\n", sum);
  return 0;
}
