#include using namespace std; int main(){ int n, m; while(cin >> n >> m){ int a[n+1]; for(int i = 0; i < n+1; i++) a[i] = 0; while(m--){ int u,v,w; cin >> u >> v >> w; if(u == v) continue; a[u] += w; a[v] += w; } sort(a+1, a+1+n); cout << a[1] << endl; } }