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 time

#start_time = time.time()
#def TIME_(): print(time.time()-start_time)

import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def getInt(): return int(input())
def getStrs(): return input().split()
def getInts(): return list(map(int,input().split()))
def getStr(): return input()
def listStr(): return list(input())
def getMat(n): return [getInts() for _ in range(n)]
def getBin(): return list(map(int,list(input())))
def isInt(s): return '0' <= s[0] <= '9'
def ceil_(a,b): return a//b + (a%b > 0)

MOD = 10**9 + 7

"""
Existing weights has XOR K
So my new weights have XOR K

I need to assign weights with XOR sum K such that the weight of the MST is minimised

Obviously once I've assigned some with XOR sum K, the rest can be 0ed

So I'm going to add exactly K to the total weights, somehow

So the question is, how much of the graph can I connect using none of the existing edges

Connect as many nodes as possible that way, then resort to existing edges. Remember that one of my edges must be K

If we can form a spanning tree from all bar one of the missing edges, the answer is 0
Take the minimum spanning tree of edges that we have to use, beyond our allowed 
"""

def solve():
    def find(a):
        if a != p[a]:
            p[a] = find(p[a])
        return p[a]
        
    def union(a, b):
        a, b = find(a), find(b)
        if a == b: return
        if size[a] > size[b]:
            a, b = b, a
        p[a] = b
        size[b] += size[a]
        return
    N, M = getInts()
    G = dd(set)
    X = 0
    edges = []
    for i in range(M):
        u, v, w = getInts()
        u -= 1
        v -= 1
        G[u].add(v)
        G[v].add(u)
        X ^= w
        h.heappush(edges,(w,u,v))
    used = [0]*N
    cons = 0
    p = [i for i in range(N)]
    size = [1]*N
    ans = 0
    for i in range(N):
        for j in range(N):
            if cons == N*(N-1)//2 - M - 1: break
            if i != j and find(i) != find(j) and j not in G[i]:
                union(i,j)
                cons += 1
                if cons == N-1: return 0
    for i in range(N):
        for j in range(N):
            if find(i) != find(j) and i not in G[j]:
                h.heappush(edges,(X,i,j))
                break
    while cons < N-1:
        w, u, v = h.heappop(edges)
        if find(u) == find(v): continue
        union(u,v)
        cons += 1
        ans += w
    return ans
    
#for _ in range(getInt()):
print(solve())
    #solve()

#TIME_()