#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double eps = 1e-9;
int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, x, a, b;
  cin >> n >> m;
  map<int, int> ows;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> x;
    ows[a] += x;
    ows[b] -= x;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += max(0, ows[i]);
  }
  cout << ans;
  return 0;
}
