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