#include <bits/stdc++.h>
using namespace std;
const int N = 202020;
long long n, m, no[N];
int main() {
  cin >> n >> m;
  memset(no, 0, sizeof(no));
  for (int i = (1); i <= (m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    no[a] += c;
    no[b] -= c;
  }
  long long ans = 0;
  for (int i = (1); i <= (n); ++i)
    if (no[i] > 0) ans += no[i];
  cout << ans;
  return 0;
}
