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;
const int MAX = 1 << 18;
vector<pair<int, int> > g[MAX];
int p[MAX];
vector<int> vec[MAX];
set<int> leaders;
bool isEdge(int u, int v) {
  auto it = lower_bound(g[u].begin(), g[u].end(), make_pair(v, 0));
  return it != g[u].end() && it->first == v;
}
int find(int v) { return p[v] == v ? v : p[v] = find(p[v]); }
bool unite(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return false;
  if ((int)((vec[u]).size()) > (int)((vec[v]).size())) swap(u, v);
  p[u] = v;
  int szu = (int)((vec[u]).size()), szv = (int)((vec[v]).size());
  vec[v].insert(vec[v].end(), vec[u].begin(), vec[u].end());
  assert((int)((vec[v]).size()) == szu + szv);
  leaders.erase(u);
  return true;
}
int main() {
  int n, m, x = 0;
  scanf("%d %d", &n, &m);
  vector<pair<int, pair<int, int> > > edges;
  edges.reserve(m);
  while (m--) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edges.push_back({w, {u, v}});
    x ^= w;
  }
  iota(p, p + n, 0);
  for (int i = (0); i < (n); ++i) {
    vec[i] = {i};
    leaders.insert(i);
  }
  int cnt = 0;
  for (int i = (0); i < (n); ++i) {
    int leader = -1;
    while (true) {
      auto it = leaders.upper_bound(leader);
      if (it == leaders.end()) break;
      leader = *it;
      if (find(i) != leader) {
        for (int v : vec[leader])
          if (!isEdge(i, v)) {
            unite(i, v);
            cnt++;
            break;
          }
      }
    }
  }
  long long ans = 0;
  int mnUnused = INT_MAX;
  sort(edges.begin(), edges.end());
  for (auto [w, uv] : edges) {
    if (unite(uv.first, uv.second))
      ans += w;
    else
      mnUnused = min(mnUnused, w);
  }
  cout << ans + (cnt == (long long)n * (n - 1) / 2 - (int)((edges).size())
                     ? min(x, mnUnused)
                     : 0)
       << '\n';
  return 0;
}
