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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7, N = 2e5 + 10;
set<array<ll, 2>> g[N];
set<ll> vis;
vector<array<ll, 2>> ng[N];
vector<ll> nxt[N];
ll p[N];
ll cnt;
ll lead[N];
set<ll> G[N];
vector<ll> comp;
void dfs(ll u) {
  comp.push_back(u);
  vector<ll> to_remove;
  for (ll v : vis) {
    if (!G[u].count(v)) {
      to_remove.push_back(v);
    }
  }
  for (ll v : to_remove) {
    vis.erase(v);
  }
  for (ll v : to_remove) {
    dfs(v);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;
  ll xr = 0;
  vector<array<ll, 3>> edge;
  for (ll i = 0; i < m; ++i) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    xr ^= w;
    G[u].insert(v);
    G[v].insert(u);
    g[u].insert({v, w});
    g[v].insert({u, w});
    edge.push_back({w, u, v});
    ng[u].push_back({v, w});
    ng[v].push_back({u, w});
  }
  ll rem = n * (n - 1) / 2 - m;
  for (ll i = 0; i < n; ++i) {
    vis.insert(i);
  }
  for (ll i = 0; i < n; ++i) {
    if (vis.count(i)) {
      vis.erase(i);
      comp.clear();
      dfs(i);
      for (ll v : comp) {
        lead[v] = cnt;
      }
      ll sz = comp.size();
      rem -= (sz - 1);
      cnt++;
    }
  }
  sort(begin(edge), end(edge));
  ll mn = 1e18;
  vector<array<ll, 3>> not_u;
  ll ans = 0;
  vector<ll> par(cnt), sz(cnt, 1);
  iota(begin(par), end(par), 0LL);
  function<ll(ll)> find = [&](ll u) {
    return u == par[u] ? u : par[u] = find(par[u]);
  };
  function<bool(ll, ll)> merge = [&](ll u, ll v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (sz[v] > sz[u]) swap(u, v);
    sz[u] += sz[v];
    par[v] = u;
    return true;
  };
  for (auto [w, x, y] : edge) {
    if (merge(lead[x], lead[y])) {
      ans += w;
    } else {
      not_u.push_back({w, x, y});
    }
  }
  if (rem != 0) {
    cout << ans << '\n';
    return 0;
  }
  ans += xr;
  for (auto [w, x, y] : not_u) {
    if (w >= xr) break;
    ans -= xr;
    ans += w;
    break;
  }
  cout << ans << '\n';
  return 0;
}
