#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, a, b, c, i, ans[N], cnt;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    ans[a] -= c;
    ans[b] += c;
  }
  for (i = 1; i <= n; i++)
    if (ans[i] > 0) cnt += ans[i];
  cout << cnt;
  return 0;
}
