#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int total = 0;
  vector<vector<int>> g(n, vector<int>(n, 0));
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a - 1][b - 1] = c;
    g[b - 1][a - 1] = -c;
    total += c;
  }
  int offset = 0;
  for (int i = 0; i < n; ++i) {
    int positive = 0;
    int negative = 0;
    for (int j = 0; j < n; ++j) {
      if (g[i][j] > 0)
        positive += g[i][j];
      else
        negative += g[i][j];
    }
    offset += min(positive, -negative);
  }
  cout << total - offset;
  return 0;
}
