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;
class dsu {
 public:
  vector<int> p;
  int n;
  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};
const int N = 2e5 + 5;
set<int> nodes;
set<int> g[N];
int tot;
void dfs(int u, dsu &d) {
  auto it = nodes.begin();
  vector<int> nxt;
  while (it != nodes.end()) {
    int v = *it;
    if (g[u].find(v) == g[u].end()) {
      d.unite(u, v);
      ++tot;
      nxt.push_back(v);
    }
    ++it;
  }
  for (int i = 0; i < (int)nxt.size(); ++i) {
    nodes.erase(nxt[i]);
  }
  for (int i = 0; i < (int)nxt.size(); ++i) {
    dfs(nxt[i], d);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    nodes.insert(i);
  }
  vector<tuple<int, int, int> > edges;
  int x = 0;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    g[u].insert(v);
    g[v].insert(u);
    x ^= w;
    edges.push_back(make_tuple(w, u, v));
  }
  dsu d(n);
  while (!nodes.empty()) {
    int u = *nodes.begin();
    nodes.erase(u);
    dfs(u, d);
  }
  int ans = 0;
  sort(edges.begin(), edges.end());
  dsu dpre = d;
  int mn = numeric_limits<int>::max();
  for (int i = 0; i < (int)edges.size(); ++i) {
    int u = get<1>(edges[i]);
    int v = get<2>(edges[i]);
    int w = get<0>(edges[i]);
    if (dpre.get(u) != dpre.get(v)) {
      if (d.get(u) != d.get(v)) {
        d.unite(u, v);
        ans += w;
      } else {
        mn = min(mn, w);
      }
    }
  }
  if (n * ((long long)n - 1) / 2 - m > tot) {
    cout << ans << endl;
  } else {
    if (x < mn) {
      cout << ans + x << endl;
    } else {
      if (n >= 100) assert(0);
      cout << ans + mn << endl;
    }
  }
  return 0;
}
