#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
vector<int> G[100];
vector<int> W[100];
vector<int> G2[100];
vector<int> W2[100];
bool visited[100];
int N, M;
void solve() {
  for (long long i = 0; i < (int)N; i++) {
    for (long long j = 0; j < (int)G[i].size(); j++) {
      int sum = W[i][j];
      for (long long k = 0; k < (int)G[G[i][j]].size(); k++) {
        if (sum >= W[G[i][j]][k]) {
          sum -= W[G[i][j]][k];
          W[G[i][j]][k] = 0;
        }
      }
    }
  }
}
int GRAPH[100][100];
int main() {
  cin >> N >> M;
  for (long long i = 0; i < (int)M; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    GRAPH[a][b] = w;
  }
  long long ans = 0;
  for (long long i = 0; i < (int)N; i++) {
    long long sum = 0;
    for (long long j = 0; j < (int)N; j++) sum += GRAPH[i][j];
    for (long long j = 0; j < (int)N; j++) sum -= GRAPH[j][i];
    ans += abs(sum);
  }
  cout << ans / 2;
  return 0;
}
