#include <bits/stdc++.h>
int debt[101];
int n, m;
void init() {
  int i;
  for (i = 1; i <= n; i++) debt[i] = 0;
}
void printDebt() {
  int i;
  printf("== PRINT DEBT == \n");
  for (i = 1; i <= n; i++) printf("%d %d\n", i, debt[i]);
  printf("\n");
}
int main() {
  int i, a, b, c;
  scanf("%d %d\n", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d\n", &a, &b, &c);
    debt[a] = debt[a] - c;
    debt[b] = debt[b] + c;
  }
  if (0) printDebt();
  int sum = 0;
  for (i = 1; i <= n; i++) {
    if (debt[i] > 0) sum = sum + debt[i];
  }
  printf("%d\n", sum);
  return 0;
}
