#include <bits/stdc++.h>
using namespace std;
int a[105];
int abs(int x) {
  if (x > 0) return x;
  return -x;
}
int main() {
  int n, m, i;
  int x, y, z;
  int ans = 0;
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  while (m--) {
    scanf("%d%d%d", &x, &y, &z);
    a[x] -= z;
    a[y] += z;
  }
  int aa = 0, bb = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] > 0)
      aa += a[i];
    else
      bb += a[i];
  }
  printf("%d\n", max(aa, -bb));
  return 0;
}
