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

from sys import stdin
from collections import defaultdict
from heapq import *

V, E = map(int, stdin.readline().split())
dic = defaultdict(lambda : {})
xor_sum = 0
for _ in range(E):
    u, v, w = map(int, stdin.readline().split())
    u -= 1
    v -= 1
    dic[u][v] = w
    dic[v][u] = w
    xor_sum ^= w

components = []
unvisited = set(range(V))
for src in range(V):
    if src not in unvisited:
        continue
    queue = [src]
    for u in queue:
        if u not in unvisited:
            continue
        unvisited.remove(u)
        to_remove = []
        for v in unvisited:
            if v not in dic[u]:
                queue.append(v)
    components.append(queue)

conv = dict()
for i in range(len(components)):
    for u in components[i]:
        conv[u] = i

BIG_V = len(components)
big_dic = defaultdict(lambda : defaultdict(lambda : float('inf')))
for u in dic:
    for v in dic[u]:
        if conv[u] == conv[v]: continue
        big_dic[conv[u]][conv[v]] = min(big_dic[conv[u]][conv[v]], dic[u][v])

mst = 0
edges = list((big_dic[0][v], v) for v in big_dic[0])
heapify(edges)
visited = set((0,))
while len(visited) < BIG_V:
    w, v = heappop(edges)
    if v in visited: continue
    visited.add(v)
    mst += w
    for vv in big_dic[v]:
        heappush(edges, (big_dic[v][vv], vv))


total_edges = V*(V-1)//2
if total_edges - (V-BIG_V) == E:
    print(mst + xor_sum)
else:
    print(mst)
