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<iostream>
#include<cstring>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define int long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
inline int read(){
	int f=1,ans=0; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=2e5+11;
int U[MAXN],V[MAXN],W[MAXN],N,M,res,col[MAXN]; map<pii,int> Ma;
struct Union{
	int f[MAXN]; void init(){for(int i=1;i<=N;i++) f[i]=i;return;}
	int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
	void merge(int x,int y){int t1=find(x),t2=find(y);f[t2]=t1;return;}
	bool same(int x,int y){return find(x)==find(y);}
}UU,U1;
queue<int> Que; set<int> s; set<int>::iterator it; int sta[MAXN];
void calc(int S){
	++col[0]; Que.push(S); s.erase(S);
	while(!Que.empty()){
		int xx=Que.front(); Que.pop(); col[xx]=col[0];
		sta[0]=0; for(it=s.begin();it!=s.end();it++) if(!Ma[mp(xx,*it)]) sta[++sta[0]]=*it,Que.push(*it);
		for(int i=1;i<=sta[0];i++) s.erase(sta[i]);
	}return;
}
struct Edge{int u,v,w,id;}E[MAXN];
bool cmp(Edge x1,Edge x2){return x1.w<x2.w;}
int siz[MAXN],real[MAXN],Ans;
signed main(){
	//freopen("D.in","r",stdin);
	N=read(),M=read(); for(int i=1;i<=M;i++) U[i]=read(),V[i]=read(),W[i]=read(),Ma[mp(U[i],V[i])]=Ma[mp(V[i],U[i])]=1,res^=W[i];
	for(int i=1;i<=N;i++) s.insert(i);
	for(int i=1;i<=N;i++) if(!col[i]) calc(i); //for(int i=1;i<=N;i++) cerr<<col[i]<<" ";cerr<<endl;
	int tot=0;
	for(int i=1;i<=N;i++) siz[col[i]]++;
	int Minn=LLONG_MAX;
	for(int i=1;i<=M;i++){
		if(col[U[i]]==col[V[i]]) real[col[U[i]]]++;
		else ++tot,E[tot].u=col[U[i]],E[tot].v=col[V[i]],E[tot].w=W[i],E[tot].id=i;
	} bool ff=1;
	for(int i=1;i<=col[0];i++) ff&=(real[i]+(siz[i]-1)==((siz[i]*(siz[i]-1))/2ll));
	sort(E+1,E+tot+1,cmp); UU.init(); U1.init();
	for(int i=1;i<=tot;i++){
		if(!UU.same(E[i].u,E[i].v)){
			Ans+=E[i].w; UU.merge(E[i].u,E[i].v);
			int id=E[i].id;
			U1.merge(U[id],V[id]);
		}
	}
	for(int i=1;i<=M;i++) if(!U1.same(U[i],V[i])) Minn=min(Minn,W[i]);
	if(ff) Ans+=min(res,Minn); 
	printf("%lld\n",Ans); 
	return 0;
}/*
4 4
2 1 14
1 4 14
3 2 15
4 3 8
 
*/