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("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));


long long powm(long long a, long long b,long long mod) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %mod;
        a = a * a %mod;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);      
}

int parent[200005];
int sz[200005];
int cnt[200005];

int find_parent(int ver)
{
    if(ver==parent[ver])
        return ver;
    return parent[ver]=find_parent(parent[ver]);
}

bool merge(int a,int b)
{
    a=find_parent(a);
    b=find_parent(b);
    if(a!=b)
    {
        if(sz[a]<sz[b])
            swap(a,b);
        cnt[a]+=cnt[b];
        sz[a]+=sz[b];
        parent[b]=a;
        return true;
    }
    return false;
}

map<pair<int,int>,int>mm;
set<int>s;
int vis[200005];
void dfs(int ver)
{
    vis[ver]=1;
    
    int prev=ver;

    while(1)
    {
        auto j=s.lower_bound(prev+1);

        if(j==s.end())
            break;

            int x=*j;
            prev=x;
            if(mm[{ver,x}])
            {
                continue;
            }
            s.erase(j);           
            merge(ver,x);
            dfs(x);
    }
}

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif

    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
        sz[i]=1;
    }


    int x,y,z;
    vector<pair<int,pair<int,int> > >edge;
    int qq=0;
    
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        mm[{x,y}]=1;
        mm[{y,x}]=1;
        qq^=z;
        edge.push_back({z,{x,y}});
    }

    sort(edge.begin(),edge.end());

    if(n<=1000)
    {
        int num=(n*(n-1))/2-m;

        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(mm[{i,j}]==0)
                {
                    if(merge(i,j))
                    {
                        num--;
                        cnt[find_parent(i)]++;
                    }
                }
            }
        }

        int ans=0;
        int mn=qq;

        if(num)
            mn=0;

        for(auto i:edge)
        {
            x=i.second.first;
            y=i.second.second;
            z=i.first;

            if(!merge(x,y) && cnt[find_parent(x)])
                mn=min(mn,z);
            else
                ans+=z;
        }

        ans+=mn;
        cout<<ans<<'\n';
    }
    else
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            s.insert(i);
        }

        for(int i=1;i<=n;i++)
        {
            if(vis[i]==0)
            {
                dfs(i);
            }
        }

        for(auto i:edge)
        {
            x=i.second.first;
            y=i.second.second;
            z=i.first;
            if(merge(x,y))
                ans+=z;            
        }
        cout<<ans<<'\n';
    }   

} 