#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, arr[100][2], a, b, c, sum;
  memset(arr, 0, sizeof(arr));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    arr[a - 1][1] += c;
    arr[b - 1][0] += c;
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i][1] - arr[i][0] > 0) sum += arr[i][1] - arr[i][0];
  }
  printf("%d\n", sum);
}
