#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z;
  cin >> n >> m;
  int arr[n + 1];
  for (int i = 0; i < n + 1; i++) arr[i] = 0;
  while (m--) {
    cin >> x >> y >> z;
    arr[x] += z;
    arr[y] -= z;
  }
  long long ans = 0;
  for (int i = 0; i < n + 1; i++)
    if (arr[i] > 0) ans += arr[i];
  cout << ans;
}
