#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> debt(n + 2, 0);
  for (int i = 0; i < m; i++) {
    int poor, rich, amt;
    cin >> poor >> rich >> amt;
    debt[poor] -= amt;
    debt[rich] += amt;
  }
  int ans = 0;
  for (int &it : debt) {
    if (it < 0) {
      ans += -it;
    }
  }
  cout << ans << "\n";
  return 0;
}
