#include using namespace std; vector ress; int n, m; int u, v, w; int main() { while (~scanf("%d %d",&n,&m)) { ress.resize(n, 0); while (m--) { cin >> u >> v >> w; if(u==v) continue; ress[u - 1] += w; ress[v - 1] += w; } sort(ress.begin(), ress.end()); cout << ress[0] << endl; ress.clear(); } return 0; }