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