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>
using namespace std;
#define ll long long
int _,n,m,s,cnt=0,fa[200005],que[200005];
ll ans=0;
set<int> v;
map<int,int> cost[200005];
struct edge{
	int x,y,w,type;
	bool operator<(const edge a) const{return w<a.w;}
}e[200005];
int get(int x){
	if (x==fa[x]) return x;
	return fa[x]=get(fa[x]);
}
bool merge(int x,int y){
	x=get(x); y=get(y);
	fa[x]=y;
	return x^y;
}
void bfs(int x){
	int i,y,head=0,tail=1;
	v.erase(x);
	que[1]=x;
	while (head^tail){
		x=que[++head];
		for (auto it=v.begin();it!=v.end();){
			y=*it;
			it++;
			if (cost[x].count(y)) continue;
			que[++tail]=y;
			cnt++;
			merge(x,y);
			v.erase(y);
		}
	}
}
void kruskal1(){
	int i;
	for (i=1;i<=m;i++)
	if (merge(e[i].x,e[i].y)){
		ans+=e[i].w;
		e[i].type=1;
	}
}
int kruskal2(){
	int i;
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=m;i++)
	if (merge(e[i].x,e[i].y))
	if (!e[i].type) return e[i].w; //type 3
	return INT_MAX;
}
int main(){
	int i,x,y,z;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
		cost[e[i].x][e[i].y]=cost[e[i].y][e[i].x]=e[i].w;
		s^=e[i].w;
	}
	for (i=1;i<=n;i++) fa[i]=i,v.insert(i);
	for (i=1;i<=n;i++)
	if (v.count(i)) bfs(i);
	sort(e+1,e+m+1);
	kruskal1();
	if (m+cnt<1ll*n*(n-1)/2) printf("%lld",ans);
	else printf("%lld",ans+min(s,kruskal2()));
	return 0;
}
