#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n + 2];
  memset(arr, 0, sizeof(arr));
  int a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    arr[a] -= c;
    arr[b] += c;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans += max(0, arr[i]);
  cout << ans << endl;
}
