#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int main() {
  file();
  fast();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v1(n + 1);
  int a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    v1[b].second += c;
    v1[a].first += c;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    v1[i].first -= v1[i].second;
    if (v1[i].first > 0) sum += v1[i].first;
  }
  cout << sum << "\n";
  return 0;
}
