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.*;

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 1e18 + 10;
    static final int MOD = (int) 1e9 + 7;

    static class To {
        int v, w;
        To(int v, int w) {
            this.v = v;
            this.w = w;
        }
    }

    static class Edge {
        int v, u, w;
        Edge(int v, int u, int w) {
            this.v = v;
            this.u = u;
            this.w = w;
        }
    }

    static ArrayList<To>[] g;
    static Edge[] edges;
    static int[] comp, par, compCntV;
    static HashSet<Integer> unused;
    static boolean[] inMst;
    static long[] compCntE;

    static void dfs(int v) {
        HashSet<Integer> neighbors = new HashSet<>();
        for (To e : g[v]) {
            neighbors.add(e.v);
        }
        HashSet<Integer> other = new HashSet<>();
        for (int u : unused) {
            if (!neighbors.contains(u))
                other.add(u);
        }
        for (int u : other) {
            comp[u] = comp[v];
            unused.remove(u);
        }
        for (int u : other) {
            dfs(u);
        }
    }

    static int find(int v) {
        if (par[v] == v)
            return v;
        return par[v] = find(par[v]);
    }

    static boolean unite(int v, int u) {
        v = find(v);
        u = find(u);
        if (v == u) return false;
        if (rand.nextInt() % 2 == 0)
            par[u] = v;
        else
            par[v] = u;
        return true;
    }

    static void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        g = new ArrayList[n]; Arrays.setAll(g, gi -> new ArrayList<>());
        edges = new Edge[m];
        int x = 0;
        for (int i = 0; i < m; i++) {
            int v = in.nextInt() - 1;
            int u = in.nextInt() - 1;
            int w = in.nextInt();
            g[v].add(new To(u, w));
            g[u].add(new To(v, w));
            edges[i] = new Edge(v, u, w);
            x ^= w;
        }
        comp = new int[n]; Arrays.fill(comp, -1);
        unused = new HashSet<>();
        for (int v = 0; v < n; v++) {
            unused.add(v);
        }
        int c = 0;
        for (int v = 0; v < n; v++) {
            if (comp[v] == -1) {
                comp[v] = c++;
                unused.remove(v);
                dfs(v);
            }
        }
        Arrays.sort(edges, (e1, e2) -> e1.w - e2.w);
        par = new int[c];
        for (int i = 0; i < c; i++) {
            par[i] = i;
        }
        long mstWeight = 0;
        inMst = new boolean[n];
        for (Edge e : edges) {
            int v = find(comp[e.v]);
            int u = find(comp[e.u]);
            if (v != u) {
                mstWeight += e.w;
                inMst[e.v] = inMst[e.u] = true;
                unite(v, u);
            }
        }
        compCntV = new int[c];
        for (int i = 0; i < n; i++) {
            compCntV[comp[i]]++;
        }
        compCntE = new long[c];
        for (int i = 0; i < c; i++) {
            compCntE[i] = 1L * compCntV[i] * (compCntV[i] - 1) / 2;
        }
        for (Edge e : edges) {
            if (comp[e.v] == comp[e.u])
                compCntE[comp[e.v]]--;
        }
        boolean cycle = false;
        for (int i = 0; i < c; i++) {
            if (compCntE[i] >= compCntV[i]) {
                cycle = true;
                break;
            }
        }
        if (cycle) {
            out.println(mstWeight);
        } else {
            int minE = x;
            for (Edge e : edges) {
                if (!inMst[e.v] || !inMst[e.u])
                    minE = Math.min(minE, e.w);
            }
            out.println(mstWeight + minE);
        }

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);

        int t = 1;
//        t = in.nextInt();
        while (t-- > 0) {
            solve();
        }

        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}
