#include using namespace std; int main() { int n, m; while(cin>>n>>m) { vector sz(n+1); for(auto it:sz) it = 0; for(int i=0; i> u >> v >> w; if(u==v) { continue; } sz[u] += w; sz[v] += w; } sort(sz.begin()+1, sz.end()); cout << sz[1] << endl; } return 0; }