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