#include <bits/stdc++.h>
using namespace std;
int main() {
  long long in[100000][2] = {0};
  long long sum = 0;
  long long out[101] = {0};
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    in[a][1] = in[a][1] + c;
    in[b][2] = in[b][2] + c;
  }
  for (long long i = 0; i <= n; i++) out[i] = abs(in[i][1] - in[i][2]);
  for (long long i = 0; i <= n; i++) sum = sum + out[i];
  cout << sum / 2 << endl;
  return 0;
}
