#include <bits/stdc++.h>
using namespace std;
int arr[103];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    arr[u] -= c;
    arr[v] += c;
  }
  long long sum = 0;
  for (int i = 0; i <= n; i++) {
    if (arr[i] >= 0) sum += arr[i];
  }
  cout << sum << endl;
  return 0;
}
