#include #include #include using namespace std; int a[3001]; const int INF=0x3f3f3f3f; int main(){ int n,m; int x,y,z; int l,sum; while(scanf("%d",&n)!=EOF){ memset(a,0,sizeof(a)); scanf("%d",&m); for(int i=1;i<=m;i++){ scanf("%d%d%d",&x,&y,&z); if(x!=y){ a[x]+=z; a[y]+=z;} } l=INF; for(int i=1;i<=n;i++){ l=min(l,a[i]); } printf("%d\n",l); } return 0; }