#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m;     int a[m];     for (int i = 0; i < m; i++) {       a[i] = 0;     }     cin >> n;     int p = 0, q = 0, r = 0;     for (int i = 0; i < n; i++) {       cin >> p;       cin >> q;       cin >> r;       a[p - 1] -= r;       a[q - 1] += r;     }     int res = 0;     for (int i = 0; i < m; i++) {       if (a[i] > 0) res += a[i];     }     cout << res;     return 0;   }   