#include <bits/stdc++.h>
using namespace std;
int l[1000], r[1000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    l[a] += w;
    r[b] += w;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += abs(l[i] - r[i]);
  cout << ans / 2 << " " << endl;
}
