#include #include #include #include #include using namespace std; int n,m,c[3010],x,y,z; int main() { while(scanf("%d%d",&n,&m)!=EOF) { memset(c,0,sizeof(c)); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); if(x==y) continue; c[x]+=z; c[y]+=z; } sort(c+1,c+1+n); printf("%d\n",c[1]); } return 0; } /* 3 1 2 3 8 0 4 7 6 5 1 2 3 5 6 7 4 0 8 */