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

//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
inline void ac();
int main(){
#ifdef MULTICASES
	int t;scanf("%d",&t);while(t--)ac();
#else
	ac();
#endif
	return 0;
}
inline void cmn(int &x,const int &a){if(a<x)x=a;}
const int MAXN=200005;
set<int>S,ES[MAXN];
namespace ufs{
	int F[MAXN];
	inline int find(const int &v){return F[v]?F[v]=find(F[v]):v;}
	inline void merge_f(const int &v,const int &u){F[find(v)]=find(u);}
	inline bool together(const int &v,const int &u){
		return find(v)==find(u);
	}
	inline bool merge(int v,int u){
		if((v=find(v))==(u=find(u)))return false;
		F[v]=u;return true;
	}
};
using ufs::merge_f;
using ufs::together;
using ufs::merge;
namespace ufs2{
	int F[MAXN];
	inline int find(const int &v){return F[v]?F[v]=find(F[v]):v;}
	inline void merge_f2(const int &v,const int &u){F[find(v)]=find(u);}
	inline bool together2(const int &v,const int &u){
		return find(v)==find(u);
	}
};
using ufs2::merge_f2;
using ufs2::together2;
inline void dfs(const int &v){
	S.erase(v);
	int u=0;
	set<int>::iterator s;
	while(true){
		s=S.upper_bound(u);
		if(s==S.end())return;
		u=*s;
		if(ES[v].count(u))continue;
		//ERR("%d -- %d\n",v,u);
		merge_f(v,u);
		dfs(u);
	}
}
struct edge{int v,u,w;inline bool operator<(const edge &e)const{return w<e.w;}}E[MAXN];
inline void ac(){
	int n,m,i,v,u,w,t=0;ll me,Ans=0ll;
	scanf("%d%d",&n,&m);me=n*(n-3ll)/2ll;
	REP(i,0,m){
		scanf("%d%d%d",&v,&u,&w);
		E[i]=(edge){v,u,w};
		ES[v].insert(u);
		ES[u].insert(v);
		t^=w;
	}
	rep(v,1,n)S.insert(v);
	rep(v,1,n)if(S.count(v)){++me;dfs(v);}
	if(m==me){
		REP(i,0,m)if(together(E[i].v,E[i].u))cmn(t,E[i].w);
	}else t=0;
	sort(E,E+m);
	//ERR("tree=%d\n",m==me);
	REP(i,0,m){
		if(merge(E[i].v,E[i].u)){merge_f2(E[i].v,E[i].u);Ans+=E[i].w;}
		else if(!together2(E[i].v,E[i].u))cmn(t,E[i].w);
	}
	printf("%lld\n",Ans+t);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/
