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

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<char>> vvc64;

typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
#define pp pair<ll, p64>
ll mpow(ll a, ll b)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2);
    t1 *= t1;
    t1 %= MOD;
    if (b % 2)
        t1 *= a;
    t1 %= MOD;
    return t1;
}
ll mpow(ll a, ll b, ll p)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2, p);
    t1 *= t1;
    t1 %= p;
    if (b % 2)
        t1 *= a;
    t1 %= p;
    return t1;
}

void norm(ll &n)
{
    n %= MOD;
    n += MOD;
    n %= MOD;
}

ll LIM = 2e5 + 100;
vector<vp64> adj(LIM);
set<ll> unvisited;
ll N;

// UnionFind U(n) :- n is number of elements

class UnionFind
{

public:
    v64 p, rank, sz;
    ll components;
    UnionFind(ll N)
    {
        rank.assign(N, 0);
        p.assign(N, 0);
        sz.assign(N, 1);
        forn(i, N) p[i] = i;
        components = N;
    }
    void inc()
    {
        rank.pb(0);
        p.pb(sz(p));
        sz.pb(1);
    }
    ll findSet(ll i)
    { // returns the head of group containing element i
        return (p[i] == i) ? i : (p[i] = findSet(p[i]));
    }
    bool isSameSet(ll i, ll j)
    { // checks whether i and j are in same group
        return findSet(i) == findSet(j);
    }
    void unionSet(ll i, ll j)
    { // unify group containing i and j(if already in same set then do nothing)
        if (!isSameSet(i, j))
        {
            ll x = findSet(i), y = findSet(j);
            if (rank[x] > rank[y])
            {
                p[y] = x;
                sz[x] += sz[y];
            }
            else
            {
                p[x] = y;
                if (rank[x] == rank[y])
                    rank[y]++;
                sz[y] += sz[x];
            }
            components--;
        }
    }
    ll sz1(ll i)
    { // returns the sz[i] (to check the size of group containing i use sz1(findSet(i)))
        return sz[i];
    }
};

void dfs(ll n, ll &cnt, UnionFind &g1)
{
    cnt++;
    unvisited.erase(n);
    if (sz(unvisited) == 0)
        return;
    adj[n].push_back({-1, -1});
    adj[n].push_back({N + 1, -1});
    sort(all(adj[n]));
    for (ll i = 1; i < sz(adj[n]); i++)
    {
        while (true)
        {
            if (sz(unvisited) == 0)
                break;
            auto it = unvisited.upper_bound(adj[n][i - 1].fi);

            if (it == unvisited.end() || *it >= adj[n][i].fi)
                break;
            else
            {
                ll child = *it;
                dfs(child, cnt, g1);
                g1.unionSet(n, child);
            }
        }
    }
}
void solve(ll t)
{
    ll n, m;
    cin >> n >> m;
    N = n;
    ll x = 0;
    vector<pp> edges;
    for (ll i = 1; i <= m; i++)
    {
        ll u, v, w;
        cin >> u >> v >> w;
        x ^= w;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
        edges.push_back({w, {u, v}});
    }
    for (ll i = 1; i <= n; i++)
        unvisited.insert(i);
    v64 s;
    UnionFind g1(N + 1), g2(N + 1);
    for (ll i = 1; i <= n; i++)
    {
        // cout << i << endl;
        if (unvisited.find(i) != unvisited.end())
        {
            // ans++;
            ll cnt = 0;
            dfs(i, cnt, g1);
            s.push_back(cnt);
        }
    }
    // cout << x << endl;
    sort(all(edges));
    ll ans = 0;
    ll sum = x;
    ll tot_edges = n * (n - 1) / 2 - m;
    bool cycle = 0;
    if (tot_edges + g1.components >= n + 2)
    {
        // ans -= x;
        cycle = 1;
    }
    if (cycle)
    {
        sum -= x;
        if (g1.components == 2)
        {
            cout << 0 << endl;
            return;
        }
    }
    assert(sum >= 0);
    for (ll i = 0; i < m; i++)
    {
        ll w = edges[i].fi;
        ll u = edges[i].se.fi;
        ll v = edges[i].se.se;
        if (g2.isSameSet(u, v))
            continue;
        g2.unionSet(u, v);
        if (!g1.isSameSet(u, v))
            sum += w;
        g1.unionSet(u, v);
        tot_edges++;
        if (w <= x)
        {
            if ((tot_edges + g1.components >= n + 2) && (cycle == 0))
            {
                // ans -= x;
                sum -= x;
                sum += w;
                assert(sum >= 0);
                cycle = 1;
            }
        }
        if (g1.components == 2)
        {
            if (w > x)
            {
                ans = sum;
                break;
            }
            else if (w <= x)
            {
                if (cycle)
                {
                    ans = sum;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}
int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    forn(i, t)
    {
        solve(i + 1);
    }
}