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;
long long n, m, x[200100], y[200100], z[200100], id[200100];
vector<long long> adj[200100];
bool vis[200100], tmp[200100];
long long sn, con[700][700];
long long rt[200100];
long long find_rt(long long u) {
  return rt[u] == u ? u : rt[u] = find_rt(rt[u]);
}
long long pid[700][700];
vector<pair<long long, pair<long long, long long> > > tot;
long long solve() {
  for (long long i = 1; i <= sn; i++) rt[i] = i;
  long long rlt = 0;
  for (auto p : tot) {
    long long u = p.second.first, v = p.second.second;
    if (u == v) continue;
    u = find_rt(u), v = find_rt(v);
    if (u == v) continue;
    rlt += p.first;
    rt[u] = v;
  }
  return rlt;
}
long long sid[200100];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  long long oth = 0;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back(v);
    adj[v].push_back(u);
    x[i] = u, y[i] = v, z[i] = w;
    oth ^= w;
  }
  vector<vector<long long> > vec;
  vector<long long> rem;
  for (long long i = 1; i <= n; i++) rem.push_back(i);
  for (long long i = 1; i <= n; i++) {
    vector<long long> cur;
    if (vis[i]) continue;
    cur.push_back(i);
    vis[i] = 1;
    id[i] = vec.size() + 1;
    for (auto &u : rem) {
      if (u == i) {
        swap(u, rem.back());
        rem.pop_back();
        break;
      }
    }
    for (auto v : cur) {
      for (auto u : adj[v]) tmp[u] = 1;
      long long sz = rem.size();
      for (long long j = 0; j < sz; j++) {
        long long u = rem[j];
        if (!tmp[u]) {
          vis[u] = 1;
          swap(rem[j], rem.back());
          rem.pop_back();
          id[u] = vec.size() + 1;
          cur.push_back(u);
          j--, sz--;
        }
      }
      for (auto u : adj[v]) tmp[u] = 0;
    }
    vec.push_back(cur);
  }
  bool fg = true;
  for (auto &V : vec) {
    for (auto u : V) tmp[u] = 1;
    long long d = 0;
    for (auto u : V)
      for (auto v : adj[u])
        if (tmp[v]) d++;
    d >>= 1;
    for (auto u : V) tmp[u] = 0;
    long long sz = V.size();
    d = sz * (sz - 1) / 2 - d;
    assert(d >= sz - 1);
    if (d >= sz) {
      fg = false;
      break;
    }
  }
  const long long inf = 1e18;
  if (!fg) {
    long long ans = 0;
    for (long long i = 1; i <= n; i++) rt[i] = i;
    for (long long i = 1; i <= m; i++) sid[i] = i;
    sid[0] = 0;
    sort(sid, sid + m, [&](long long i, long long j) { return z[i] < z[j]; });
    for (long long j = 0; j < m; j++) {
      long long i = sid[j];
      long long u = find_rt(id[x[i]]), v = find_rt(id[y[i]]);
      if (u == v) continue;
      rt[u] = v, ans += z[i];
    }
    cout << ans << '\n';
  } else {
    sn = n;
    assert(m + n >= n * (n - 1) / 2 && n < 700);
    for (long long i = 1; i <= sn; i++)
      for (long long j = 1; j <= sn; j++) con[i][j] = inf;
    for (long long i = 0; i < m; i++) {
      long long u = x[i], v = y[i];
      con[u][v] = min(con[u][v], z[i]);
      con[v][u] = con[u][v];
    }
    for (long long i = 1; i <= sn; i++)
      for (long long j = 1; j <= sn; j++)
        if (con[i][j] == inf) con[i][j] = 0;
    for (long long i = 1; i <= sn; i++)
      for (long long j = 1; j < i; j++)
        tot.emplace_back(con[i][j], pair<long long, long long>(i, j));
    tot.emplace_back(oth, pair<long long, long long>(0, 0));
    sort(tot.begin(), tot.end());
    long long k = 0;
    for (auto p : tot) {
      long long u = p.second.first, v = p.second.second;
      pid[u][v] = pid[v][u] = k++;
    }
    long long ans = inf;
    for (long long i = 1; i <= sn; i++)
      for (long long j = 1; j < i; j++) {
        if (con[i][j] == 0) {
          long long a = pid[0][0], b = pid[i][j];
          swap(tot[a].second, tot[b].second);
          ans = min(ans, solve());
          swap(tot[a].second, tot[b].second);
        }
      }
    assert(ans < inf);
    cout << ans << '\n';
  }
  return 0;
}
