#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N + 1);
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    v[a] -= c;
    v[b] += c;
  }
  int answer = 0;
  for (int i = 1; i <= N; ++i) {
    if (v[i] < 0) {
      answer += -v[i];
    }
  }
  cout << answer << "\n";
  return 0;
}
