#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int debt[1000];
int main() {
  fast();
  int n, a, b, c, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    cin >> a >> b >> c;
    debt[a - 1] -= c;
    debt[b - 1] += c;
  }
  long long ans = 0;
  for (int i = 0; i < (int)(n); ++i) {
    if (debt[i] > 0) ans += debt[i];
  }
  cout << ans << "\n";
}
