#include <bits/stdc++.h>
using namespace std;
void file() {}
const int MN = 1e4 + 5;
const int MW = 1e3 + 5;
const int OO = 1e9 + 5;
int main() {
  file();
  int n, m, a, b, c, ow[101];
  memset(ow, 0, sizeof(ow));
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0;
       i < m and scanf("%d", &a) and scanf("%d", &b) and scanf("%d", &c);
       ow[a] += c, ow[b] -= c, ++i)
    ;
  long long int sm = 0;
  for (int i = 1; i <= n; ++i) sm += ((ow[i] > 0) ? ow[i] : 0);
  printf("%lld ", sm);
  return 0;
}
