#include using namespace std; int g[3333][3333]; int main() { int n, m; while (cin >> n >> m) { memset(g, 0, sizeof g); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; g[a][b] += c; g[b][a] += c; } int res = INT_MAX; for (int i = 1; i <= n; i++) { int t = 0; for (int j = 1; j <= n; j++) { if (i == j) continue; t += g[i][j]; } res = min(res, t); } cout << res << endl; } return 0; }