#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e8;
int n, m;
int t[105];
int main() {
  cin >> n >> m;
  int sum = 0;
  memset(t, 0, sizeof(t));
  for (int i = (1); i < (int)(m + 1); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    t[a] += c;
    t[b] -= c;
  }
  for (int i = (1); i < (int)(n + 1); ++i) {
    sum += max(t[i], 0);
  }
  cout << sum << endl;
  return 0;
}
