#include <bits/stdc++.h>
using namespace std;
int g[110];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  while (m--) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    g[u] -= w, g[v] += w;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (g[i] > 0) ans += g[i];
  cout << ans << endl;
  return 0;
}
