#include <bits/stdc++.h>
using namespace std;
int mat[111][111];
int arr[111];
int main() {
  memset(mat, 0, sizeof mat);
  memset(arr, 0, sizeof arr);
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;
    mat[u][v] = c;
    arr[v] += c;
    arr[u] -= c;
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    if (arr[i] > 0) ans += arr[i];
  }
  cout << ans << endl;
  return 0;
}
