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
input = sys.stdin.readline
n,m=map(int,input().split())
neig=[0]*n
su=0
for i in range(n):
    neig[i]={}
edges=[]
for i in range(m):
    v1,v2,w=map(int,input().split())
    v1-=1
    v2-=1
    su=su^w
    edges.append([w,v1,v2])
    neig[v1][v2]=w
    neig[v2][v1]=w
edges.sort()
na=set(range(n))
grs=[-1]*n
gps=[]
cur=0
for i in range(n):
    if i in na:
        na.remove(i)
        tod=[i]
        gps.append([i])
        while len(tod):
            j=tod.pop()
            grs[j]=cur
            tor=set()
            for x in na:
                if x not in neig[j]:
                    tod.append(x)
                    tor.add(x)
                    gps[-1].append(x)
            na-=tor
        cur+=1
ans=0
prob=0
if n-cur==((n-1)*n)//2-m:
    prob=1
cheapest=0
for e in edges:
    if grs[e[1]]==grs[e[2]]:
        cheapest= e[0]
        break
for e in edges:
    if grs[e[1]]!=grs[e[2]]:
        ans+=e[0]
        g1=grs[e[1]]
        g2=grs[e[2]]
        if len(gps[g1])>len(gps[g2]):
            g1,g2=g2,g1
        for x in gps[g1]:
            grs[x]=g2
            gps[g2].append(x)
if prob:
    ans+=min(su,cheapest)
print(ans)