#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int mat[N][N];
int main() {
  int n, m;
  int a, b, c;
  while (cin >> n >> m) {
    memset(mat, 0, sizeof(mat));
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      mat[a][b] += c;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        sum += mat[i][j];
        sum -= mat[j][i];
      }
      ans += abs(sum);
    }
    cout << abs(ans >> 1) << endl;
  }
  return 0;
}
