#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 3333; const int MOD = 1e9+7; const LL inf = 0x3f3f3f3f; const double eps= 1e-8; const double pi = acos(-1.0); int n,m,t,tot,cnt,ret,ans,tmp; inline int read() { int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { c=c*10+ch-'0'; ch=getchar(); } return c*f; } int fa[maxn],du[maxn]; int find(int x)// { if(x==fa[x]) return x; return fa[x]=find(fa[x]); } void init() { for(int i=1; i<=n; ++i) fa[i]=i,du[i]=0; } int main() { //freopen("in.txt","r",stdin); while(~scanf("%d%d",&n,&m)) { init(); tot=0;//不连通 for(int i=1; i<=m; ++i) { int u,v,w; u=read();v=read();w=read(); if(u==v) continue; du[u]+=w; du[v]+=w; if(find(u)!=find(v)) { ++tot; // fa[u]=fa[v]; fa[find(u)]=find(v); } } if(tot!=n-1)//图本身不连通 { puts("0"); continue; } ret=du[1]; for(int i=2; i<=n; ++i) ret=min(du[i],ret); printf("%d\n",ret); } return 0; }