#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> deb(n + 1);
  vector<int> own(n + 1);
  for (int i = 1, a, c, b; i <= m; i++) {
    cin >> a >> b >> c;
    own[a] += c;
    deb[b] += c;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (deb[i] < own[i]) sum += own[i] - deb[i];
  }
  cout << sum;
  return 0;
}
