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;
struct dsu {
  void resize(ll n) {
    rt.resize(n);
    for (ll i = 0; i < n; ++i) rt[i] = i;
    sz.assign(n, 1);
  }
  ll gst(ll i) {
    if (rt[i] == i) return i;
    return rt[i] = gst(rt[i]);
  }
  ll gsz(ll i) { return sz[gst(i)]; }
  void unite(ll i, ll j) {
    i = gst(i);
    j = gst(j);
    if (i == j) return;
    if (sz[i] > sz[j])
      rt[j] = i, sz[i] += sz[j];
    else
      rt[i] = j, sz[j] += sz[i];
  }

 private:
  vector<ll> rt;
  vector<ll> sz;
};
const ll MAXN = 2e5 + 123;
vector<ll> edg[MAXN];
vector<pair<ll, pair<ll, ll>>> edgvl;
ll cntin[MAXN];
dsu su;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll n, m;
  ll xr = 0;
  cin >> n >> m;
  for (ll i = 0; i < m; ++i) {
    ll u, v, c;
    cin >> u >> v >> c;
    --v, --u;
    edg[v].push_back(u);
    edg[u].push_back(v);
    edgvl.push_back({c, {u, v}});
    xr ^= c;
  }
  su.resize(n);
  set<pair<ll, ll>> st;
  for (ll i = 0; i < n; ++i) st.insert({0, i});
  while (st.size()) {
    ll v = st.begin()->second;
    st.erase(st.begin());
    for (auto u : edg[v]) {
      if (st.find({cntin[u], u}) != st.end()) {
        st.erase({cntin[u], u});
        ++cntin[u];
        st.insert({cntin[u], u});
      }
    }
    if (st.size() && st.begin()->first < n - st.size()) {
      su.unite(v, st.begin()->second);
    }
  }
  map<int, int> cntrb;
  for (int i = 0; i < m; ++i) {
    auto [c, e] = edgvl[i];
    auto [u, v] = e;
    if (su.gst(u) == su.gst(v)) {
      ++cntrb[su.gst(u)];
    }
  }
  for (int i = 0; i < n; ++i) {
    ll sz = su.gsz(i);
    ll rb = cntrb[su.gst(i)];
    if (sz * (sz - 1) / 2 - rb >= sz) xr = 0;
  }
  sort(edgvl.begin(), edgvl.end());
  ll ans = 0;
  for (ll i = 0; i < m; ++i) {
    auto [c, e] = edgvl[i];
    auto [u, v] = e;
    if (su.gst(u) != su.gst(v)) {
      su.unite(u, v);
      ans += c;
    } else {
      xr = min(xr, c);
    }
  }
  cout << ans + xr;
}
