#include <bits/stdc++.h>
using namespace std;
struct person {
  int money;
  int debt;
};
person tab[100];
int main() {
  int people, debts = 0;
  scanf("%d %d", &people, &debts);
  for (int i = 0; i < debts; i++) {
    int a = 0, b = 0, c = 0;
    scanf("%d %d %d", &a, &b, &c);
    tab[b - 1].money += c;
    tab[a - 1].debt += c;
  }
  int sum = 0;
  for (int i = 0; i < people; i++) {
    if (tab[i].debt >= tab[i].money)
      tab[i].debt -= tab[i].money;
    else
      tab[i].debt = 0;
    sum += tab[i].debt;
  }
  printf("%d\n", sum);
  return 0;
}
