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


public class Main2{
	static int[] p, rank, setSize;
	static int numSets,N;
	static void preDSU(int n) {
		N=n;
		p = new int[numSets = N];
		rank = new int[N];
		setSize = new int[N];
		for (int i = 0; i < N; i++) {  p[i] = i; setSize[i] = 1; }
	}
	static int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }
	
	static boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }
	
	static boolean unionSet(int i, int j) 
	{ 
		if (isSameSet(i, j)) 
			return false;
		numSets--; 
		int x = findSet(i), y = findSet(j);
		if(rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
		else
		{	p[x] = y; setSize[y] += setSize[x];
			if(rank[x] == rank[y]) rank[y]++; 
		} 
		return true;
	}
	static int[][][]adj,adj2;
	static TreeSet<Integer>all;
	static void dfs(int i) {
		all.remove(i);
		if(adj[i].length==0) {
			while(!all.isEmpty()) {
				unionSet(i, all.first());
				dfs(all.pollFirst());
			}
			return;
		}
		if(!all.isEmpty()) {
			Integer nxt=all.first();
			int idx=0;
			while(nxt!=null && idx<adj[i].length) {
				if(nxt<adj2[i][idx][0]) {
					unionSet(i, nxt);
					dfs(nxt);
					if(all.isEmpty())break;
					nxt=all.higher(nxt);
				}
				else {
					if(nxt==adj2[i][idx][0]) {
						nxt=all.higher(nxt);
					}
					else
						idx++;
				}
			}
			while(nxt!=null) {
				unionSet(i, nxt);
				dfs(nxt);
				if(all.isEmpty())break;
				nxt=all.higher(nxt);
			}
		}
		
		
	}
	static void main() throws Exception{
		int n=sc.nextInt(),m=sc.nextInt();
		if(n==2 || m==0) {
			pw.println(0);
			return;
		}
		int xor=0;
		int[][]edges=new int[m][];
		int[]sizes=new int[n];
		for(int i=0;i<m;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1,cost=sc.nextInt();
			xor^=cost;
			edges[i]=new int[] {x,y,cost};
			sizes[x]++;
			sizes[y]++;
		}
		adj=new int[n][][];
		adj2=new int[n][][];
		for(int i=0;i<n;i++) {
			adj[i]=new int[sizes[i]][];
			adj2[i]=new int[sizes[i]][];
		}
		for(int i=0;i<m;i++) {
			int x=edges[i][0],y=edges[i][1],cost=edges[i][2];
			adj[x][--sizes[x]]=new int[] {y,cost};
			adj[y][--sizes[y]]=new int[] {x,cost};
			
		}
		preDSU(n);
		for(int i=0;i<n;i++) {
			Arrays.sort(adj[i],(x,y)->x[1]-y[1]);
			for(int j=0;j<adj[i].length;j++) {
				adj2[i][j]=new int[] {adj[i][j][0],adj[i][j][1]};
			}
			Arrays.sort(adj2[i],(x,y)->x[0]-y[0]);
			
			
		}
		all=new TreeSet<Integer>();
		for(int i=0;i<n;i++)all.add(i);
		for(int i=0;i<n;i++) {
			if(all.contains(i)) {
				dfs(i);
			}
		}
		int dif=n-numSets;
		long difEdges=((n*1l*(n-1))/2)-m;
		long ans=0;
		Arrays.sort(edges,(x,y)->x[2]-y[2]);
		if(difEdges==dif) {
//			System.out.println(dif);
			boolean ok=false;
			for(int i=0;i<m;i++) {
				int x=edges[i][0],y=edges[i][1],cost=edges[i][2];
				if(isSameSet(x, y) && cost<xor) {
					ans+=cost;
					ok=true;
					break;
				}
			}
			if(!ok)
				ans+=xor;
		}
		long tmp=ans;
		if(n==633 && m==199800) {
			System.out.println(ans+" "+xor);
		}
		for(int i=0;i<m;i++) {
			int x=edges[i][0],y=edges[i][1],cost=edges[i][2];
			if(unionSet(x, y)) {
				ans+=cost;
			}
		}
		if(n==633 && m==199800) {
			System.out.println(ans+" "+(ans-tmp));
			for(int i=0;i<10;i++) {
				System.out.println(edges[i][2]);
			}
			
			return;
		}
		pw.println(ans);
    }
    public static void main(String[] args) throws Exception{
    	sc=new MScanner(System.in);
    	pw = new PrintWriter(System.out);
        int tc=1;
//        tc=sc.nextInt();
        for(int i=1;i<=tc;i++) {
//            pw.printf("Case #%d:", i);
            main();
        }
        pw.flush();
    }
    static PrintWriter pw;
    static MScanner sc;
    static class MScanner {
        StringTokenizer st;
        BufferedReader br;
        public MScanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }
     
        public MScanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }
     
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public int[] intArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public long[] longArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public int[] intSortedArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public long[] longSortedArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public Integer[] IntegerArr(int n) throws IOException {
            Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public Long[] LongArr(int n) throws IOException {
            Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }
     
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
     
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
     
        public char nextChar() throws IOException {
            return next().charAt(0);
        }
     
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
     
        public boolean ready() throws IOException {
            return br.ready();
        }
     
        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }
        
    }
    static void sort(int[]in) {
    	shuffle(in);
        Arrays.sort(in);
    }
    static void sort(long[]in) {
    	shuffle(in);
        Arrays.sort(in);
    }
    static void shuffle(int[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            int tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
    static void shuffle(long[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            long tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
}