#include <bits/stdc++.h>
int vis[105];
int main() {
  int n, m, i, a, b, c;
  scanf("%d%d", &n, &m);
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    vis[a] -= c;
    vis[b] += c;
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    if (vis[i] > 0) {
      ans += vis[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}
