#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 100001;
const int inf = 1000000005;
int n, m;
int a[N], b[N], c[N], d[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    d[a[i]] += c[i];
    d[b[i]] -= c[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (d[i] > 0) ans += d[i];
  printf("%d\n", ans);
  return 0;
}
