#include using namespace std; const int maxn = 3e3 + 5; long long cost[maxn]; int main() { int n, m; int u, v; long long c; while(scanf("%d%d", &n, &m) != EOF) { memset(cost, 0, sizeof(cost)); for(int i = 1; i <= m; ++i) { scanf("%d%d%I64d", &u, &v, &c); if(u == v) continue; cost[u] += c; cost[v] += c; } sort(cost + 1, cost + 1 + n); // for(int i = 1; i < n + 1; i++) { // if(cost[i] != 0) { // printf("%I64d\n", cost[i]); // break; // } // } printf("%I64d\n", cost[1]); } return 0; }