#include <bits/stdc++.h>
using namespace std;
int arr[102][2];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    arr[a][0] += c;
    arr[b][1] += c;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i + 1][1] - arr[i + 1][0] > 0) sum += arr[i + 1][1] - arr[i + 1][0];
  }
  cout << sum;
  return 0;
}
