#include <bits/stdc++.h>
const int SIZE = 1e2 + 5;
using namespace std;
int Inc[SIZE];
int Dec[SIZE];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  while (m-- > 0) {
    int x, y, z;
    cin >> x >> y >> z;
    Inc[x] += z;
    Dec[y] += z;
  }
  int Ans = 0;
  for (int i = 1; i < n + 1; i++)
    if (Dec[i] > Inc[i]) Ans += (Dec[i] - Inc[i]);
  cout << Ans;
}
