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

import sys, os

if os.environ['USERNAME']=='kissz':
    inp=open('in.txt','r').readline
    def debug(*args):
        print(*args,file=sys.stderr)
else:
    inp=sys.stdin.readline    
    def debug(*args):
        pass

# SCRIPT STARTS HERE

def getp(i):
    L=[]
    while parent[i]>=0:
        L+=[i]
        i=parent[i]
    for j in L:
        parent[j]=i
    return i
    

n,m=map(int,inp().split())
neighbors=[[] for _ in range(n)]
E=[]
deg=[0]*n
xors=0
for _ in range(m):
    u,v,w=map(int,inp().split())
    neighbors[u-1].append(v-1)
    neighbors[v-1].append(u-1)
    E+=[(w,v-1,u-1)]
    xors^=w

s=0
parent=[-1]*n
k=(n*(n-1))//2-m
conn=0
for i in range(n):
    for j in range(n):
        if j in neighbors[i]: continue
        pj=getp(j)
        if i!=pj:
            parent[i]=pj
            conn+=1
            debug(i,j,0)
            neighbors[j]+=[i]
            k-=1
            break

E.sort()
         
        
if conn<n-1:
    for w,u,v in E:
        pu=getp(u)
        pv=getp(v)
        if pu!=pv:
            s+=w
            parent[u]=pv
            conn+=1
            debug(u,v,w)
        if conn>=n-1:
            break        
                
if k==0:
    for w,u,v in E:
        if w>=xors:
            s+=xors
            debug('no corr ', xors)
            break
        else:
            pu=getp(u)
            pv=getp(v)
            if pu==pv:
                s+=w
                debug('corr ',u,v,w)
                break   
            
print(s)

