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('in3.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=[set() for _ in range(n)]
G=[[] for _ in range(n)]
E=[]
xors=0
for _ in range(m):
    u,v,w=map(int,inp().split())
    neighbors[u-1].add(v-1)
    neighbors[v-1].add(u-1)
    E+=[(w,v-1,u-1)]
    xors^=w

s=0
parent=[-1]*n
k=(n*(n-1))//2-m
nodes=set(range(n))
conn=0
for p in range(n):
    if p not in nodes: continue
    nodes.remove(p)
    Q=[p]
    while Q:
        i=Q.pop()
        new_nodes=set()
        for j in nodes:
            if j not in neighbors[i]:
                parent[j]=p
                G[i].append((j,True))
                G[j].append((i,True))
                new_nodes.add(j)
                conn+=1
                debug(i,j,0)
                k-=1   
                Q.append(j)
        nodes-=new_nodes
debug(parent)       
if conn<n-1 or k==0:
    E.sort()
    for w,u,v in E:
        pu=getp(u)
        pv=getp(v)
        if pu!=pv:
            s+=w
            parent[pu]=pv
            G[u].append((v,False))
            G[v].append((u,False))
            conn+=1
            debug(u,v,w)
        elif k==0 and w<xors:
            Q=[(u,False)]
            seen=[False]*n
            seen[u]=True
            while Q:
                i,new=Q.pop()
                for j,new_edge in G[i]:
                    if not seen[j]:
                        seen[j]=True
                        new_edge |= new
                        if j==v:
                            Q=[]
                            break
                        else:
                            Q.append((j,new_edge))
            if new_edge:
                s+=w
                debug('corr ',u,v,w)
                k+=1;  
        if conn>=n-1 and (k>0 or w>xors):
            break     
                
if k==0:
    s+=xors
    debug('no corr ', xors)
        
            
print(s)

