#include <bits/stdc++.h>
using namespace std;
int main() {
  int deb[105], ow[105], N, M;
  memset(deb, 0, sizeof deb);
  memset(ow, 0, sizeof ow);
  scanf("%d%d", &N, &M);
  int a, b, c;
  while (M--) {
    scanf("%d%d%d", &a, &b, &c);
    deb[b] += c;
    ow[a] += c;
  }
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    if (deb[i] < ow[i]) sum += ow[i] - deb[i];
  }
  printf("%d", sum);
}
