#include <bits/stdc++.h>
using namespace std;
void File() { freopen("tshirts.in", "r", stdin); }
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e4 + 5;
const int oo = 0x3f3f3f3f;
int main() {
  fast();
  int n, m;
  int arr[102] = {};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    arr[a] -= c;
    arr[b] += c;
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] >= 0) res += arr[i];
  }
  cout << res << "\n";
  return 0;
}
