#include <bits/stdc++.h>
using namespace std;
int arr[120];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, x, y, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> c;
    x--;
    y--;
    arr[x] -= c;
    arr[y] += c;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > 0) {
      res += arr[i];
    }
  }
  cout << res << endl;
  return 0;
}
