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 java.util.*;
import java.io.*;

public class C1508 {
	static HashMap<Integer, Integer>[] adjList;

	public static long mst(int n, int m, int xor) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(0);
		HashSet<Integer> notVis = new HashSet<Integer>();
		for (int i = 1; i < n; i++) {
			notVis.add(i);
		}
		PriorityQueue<int[]> edgePool = new PriorityQueue<int[]>((u, v) -> u[1] - v[1]);
		boolean[] inQueue = new boolean[n];
		inQueue[0] = true;
		int cntEdge = 0;
		long ans = 0;
		int cntZeroEdges = 0;
		while (cntEdge != n - 1) {
			while (!q.isEmpty()) {
				int cur = q.poll();
				Stack<Integer> removed = new Stack<Integer>();
				for (int x : notVis) {
					if (adjList[cur].containsKey(x)) {
						edgePool.add(new int[] { x, adjList[cur].get(x) });
					} else {
						removed.add(x);
						if (!inQueue[x]) {
							cntEdge++;
							cntZeroEdges++;
							q.add(x);
							inQueue[x] = true;
						}
					}
				}
				while (!removed.isEmpty()) {
					notVis.remove(removed.pop());
				}

			}
			if (cntEdge != n - 1) {
				while (!edgePool.isEmpty()) {
					int[] cur = edgePool.poll();
					if (!inQueue[cur[0]]) {
						q.add(cur[0]);
						inQueue[cur[0]] = true;
						ans += cur[1];
						cntEdge++;
						break;
					}
				}
			}
		}
		long remZeroEdges = 1l * n * (n - 1) / 2 - m - cntZeroEdges;
		if (remZeroEdges > 0) {
			return ans;
		}
		return ans + xor;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();
		adjList = new HashMap[n];
		for (int i = 0; i < adjList.length; i++) {
			adjList[i] = new HashMap<Integer, Integer>();
		}
		int xor = 0;
		for (int i = 0; i < m; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			int w = sc.nextInt();
			adjList[u].put(v, w);
			adjList[v].put(u, w);
			xor ^= w;
		}
		pw.println(mst(n, m, xor));
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = Integer.parseInt(next());
			}
			return arr;
		}

	}

}
