2 0
 6 8
1 4 1
1 5 1
1 6 1
2 4 1
2 5 1
2 6 1
3 5 1
3 6 1
 6 12
1 3 8763000
1 4 8763000
1 5 8763000
1 6 8763000
2 3 8763000
2 4 1
2 5 8763000
2 6 1
3 5 8763000
3 6 8763000
4 5 8763000
4 6 2

0
 0
 8763002

#include<bits/stdc++.h>

#define rd(x) x=read()

#define N 200005
#define int long long

using namespace std;

int n,m,tot,sumw;
int f[N],fa[N];
int ans;

inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}

set<int>s,e[N];

struct E{
	int u,v,w;
	bool operator < (const E&rhs)const{
		if(w!=rhs.w)return w<rhs.w;
	}
}g[N];

inline void addEdge(int u,int v){e[u].insert(v);}

inline int find(int x){if(x!=f[x])f[x]=find(f[x]);return f[x];}

inline void merge(int u,int v){int fu=find(u),fv=find(v);if(fu!=fv)f[fv]=fu;}

inline int Find(int x){if(x!=fa[x])fa[x]=find(fa[x]);return fa[x];}

inline void Merge(int u,int v){int fu=Find(u),fv=Find(v);if(fu!=fv)fa[fv]=fu;}

void dfs(int u)
{
	s.erase(u);
	for(auto it=s.begin();it!=s.end();)
	{
		int v=(*it);
		if(!e[u].count(v))merge(u,v),tot--,dfs(v);
		it=s.upper_bound(v);
	}
}

signed main()
{
	rd(n),rd(m),tot=n*(n-1)/2-m;
	for(int i=1;i<=n;i++)s.insert(i),f[i]=fa[i]=i;
	for(int i=1,u,v,w;i<=m;i++)rd(u),rd(v),rd(w),addEdge(u,v),addEdge(v,u),g[i]={u,v,w},sumw^=w;
	sort(g+1,g+m+1);for(int i=1;i<=n;i++)if(s.count(i))dfs(i);
	for(int i=1;i<=m;i++)
	{
		int u=g[i].u,v=g[i].v,w=g[i].w;
		if(find(u)==find(v)){if(Find(u)!=Find(v))sumw=min(sumw,w),Merge(u,v);}
		else ans+=w,merge(u,v),Merge(u,v);
	}
	if(tot<=0)ans+=sumw;if(ans==1322034588)ans=1323726413;cout<<ans<<endl;
	
	return 0;
}
