#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int MAXN = 1000000 + 100;
const int INF = 0x6fffffff;
const int inf = 522133279;
const long long LLinf = 1e30;
int person[1000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    person[a] += w;
    person[b] -= w;
  }
  long long cnt = 0;
  for (int i = 0; i <= n; i++)
    if (person[i] < 0) cnt += -person[i];
  cout << cnt << endl;
}
