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 all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
 
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 200000;

int N, M;
vector<pii> gp[MAX_N+1];
struct S{
	int x, y, z;
	bool operator <(const S &a)const{
		return z<a.z;
	}
};
vector<S> edge;
bool tf = false;

int g[MAX_N+1];
int g2[MAX_N+1];

void ig(){
	for(int i=1; i<=N; i++)	g[i] = i;
}

int fg(int x){
	return (g[x]==x)?(x):(g[x]=fg(g[x]));
}


void ug(int x, int y){
	x = fg(x); y = fg(y);
	g[x] = y;
}

void ig2(){
	for(int i=1; i<=N; i++)	g2[i] = i;
}

int fg2(int x){
	return (g2[x]==x)?(x):(g2[x]=fg2(g2[x]));
}


void ug2(int x, int y){
	x = fg2(x); y = fg2(y);
	g2[x] = y;
}

bool chk[MAX_N+1];

void dfs1(int x){
	if(tf)	return;
	int idx = 0;
	for(int i=1; i<=N; i++){
		if(idx<gp[x].size()){
			if(gp[x][idx].first==i){
				idx++;
				continue;
			}
		}
		if(i<=x)	continue;
		if(fg(x)==fg(i)){
			//cout<<"*"<<x<<" "<<i<<endl;
			tf = true;
			break;
		}
		//cout<<x<<" "<<i<<endl;
		ug(x, i);
	}
}

bool vst[MAX_N+1];
vector<int> vt, vt2;
vector<int> v;

void dfs2(int x){
	if(vst[x])	return;
	vst[x] = true;
	int idx = 0;
	for(int i=0; i<vt.size(); i++){
		while(idx<gp[x].size() && gp[x][idx].first<vt[i]){
			//cout<<"!"<<x<<" "<<gp[x][idx].first<<endl;
			idx++;
		}
		if(idx>=gp[x].size() || gp[x][idx].first!=vt[i]){
			//cout<<"U"<<vt[i]<<" "<<x<<endl;
			ug(vt[i], x);
			v.pb(vt[i]);
		}else{
			vt2.pb(vt[i]);
		}
	}
	vt.clear();
	for(int i=0; i<vt2.size(); i++){
		vt.pb(vt2[i]);
	}vt2.clear();
}

int main(){
	scanf("%d%d", &N, &M);
	ig();
	for(int i=1; i<=M; i++){
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		gp[a].pb({b, c}); gp[b].pb({a, c});
		edge.pb({a, b, c});
	}
	for(int i=1; i<=N; i++){
		sort(gp[i].begin(), gp[i].end());
	}
	for(int i=1; i<=N; i++){
		dfs1(i);	
	}
	ig();
	for(int i=1; i<=N; i++){
		if(vst[i])	continue;
		for(int j=1; j<=N; j++){
			if(j!=i){
				vt.pb(j);
			}
		}
		dfs2(i);
		while(!v.empty()){
			int t = v.back(); v.pop_back();
			dfs2(t);
		}
		vt.clear();
	}
	ll ans = 0LL;
	ll ans2 = 0LL;
	if(tf){
		ans = 0LL;
	}else{
		for(int i=0; i<M; i++){
			ans = (ans ^ (ll)(edge[i].z));
		}
		//cout<<ans<<endl;
		for(int i=0; i<M; i++){
			if(fg(edge[i].x)==fg(edge[i].y)){
				ans = min(ans, (ll)edge[i].z);
			}
		}
	}
	ans2 = ans;
	ll mn = INFLL;
	ig2();
	sort(edge.begin(), edge.end());
	for(int i=0; i<edge.size(); i++){
		if(fg(edge[i].x)!=fg(edge[i].y)){
			ans+=(ll)edge[i].z;
			ug(edge[i].x, edge[i].y);
			ug2(edge[i].x, edge[i].y);
		}else{
			if(fg2(edge[i].x)!=fg2(edge[i].y)){
				mn = min((ll)edge[i].z, mn);
			}
		}
	}
	ans = min(ans, ans-ans2+mn);
	printf("%lld\n", ans);

	return 0;
}

