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