#include #define N 200005 #define LL long long #define inf 1047483647 using namespace std; int n,m,tmp,tot,s[N],f[N],fir[N],nxt[N],son[N],w[N],vis[N],col[N]; inline void add(int x,int y,int z){son[++tot]=y,nxt[tot]=fir[x],fir[x]=tot,w[tot]=z;} inline int gf(int x){return f[x]==x?x:f[x]=gf(f[x]);} inline void uni(int x,int y){f[gf(x)]=gf(y);} inline void dfs(int x,int y){vis[x]=y,col[x]=tmp;for(register int i=fir[x];i;i=nxt[i]) if(vis[son[i]]^y) dfs(son[i],y);} struct FastIO{ static const int S=1048576; char buf[S],*L,*R;int stk[20],Top;~FastIO(){clear();} inline char nc(){return L==R&&(R=(L=buf)+fread(buf,1,S,stdin),L==R)?EOF:*L++;}inline void clear(){fwrite(buf,1,Top,stdout);Top=0;} inline void pc(char ch){Top==S&&(clear(),0);buf[Top++]=ch;}inline void endl(){pc('\n');} FastIO& operator >> (char&ch){while(ch=nc(),ch==' '||ch=='\n');return *this;} templateFastIO& operator >> (T&ret){ ret=0;int f=1;char ch=nc();while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=nc();} while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=nc();}ret*=f;return *this; } FastIO& operator >> (char* s){int Len=0;char ch=nc();while(ch!='\n'){*(s+Len)=ch;Len++;ch=nc();}} templateFastIO& operator << (T x){ if(x<0){pc('-');x=-x;}do{stk[++stk[0]]=x%10;x/=10;}while(x); while(stk[0]) pc('0'+stk[stk[0]--]);return *this; } FastIO& operator << (char ch){pc(ch);return *this;} FastIO& operator << (string str){int Len=str.size()-1;for(stk[0]=0;Len>=0;Len--) stk[++stk[0]]=str[Len];while(stk[0]) pc(stk[stk[0]--]);return *this;} }fin,fout; int main(){ // freopen("data.in","r",stdin); while(scanf("%d%d",&n,&m)!=EOF){ tot=0;for(register int i=1;i<=n;i++) fir[i]=0,f[i]=i;int ans=2147483647; for(register int i=1,x,y,z;i<=m;i++) scanf("%d%d%d",&x,&y,&z),(x^y)&&(add(x,y,z),add(y,x,z),uni(x,y),0); bool flg=0;for(register int i=2;i<=n;i++) if(gf(i)^gf(1)){flg=1;break;} if(flg){puts("0");continue;} for(register int i=1;i<=n;i++){ tmp=0,vis[i]=i;for(register int j=fir[i];j;j=nxt[j]) if(vis[son[j]]^i) tmp++,dfs(son[j],i); for(register int j=1;j<=tmp;j++) s[j]=0;for(register int j=fir[i];j;j=nxt[j]) s[col[son[j]]]+=w[j]; for(register int j=1;j<=tmp;j++) ans=min(ans,s[j]); // cout<