#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> n >> m;
  int huydth[101] = {0};
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    huydth[a] = huydth[a] + c;
    huydth[b] = huydth[b] - c;
  }
  long int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (huydth[i] > 0) sum += huydth[i];
  }
  cout << sum;
  return 0;
}
