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;
int n, m, W;
set<int> alive;
set<int> from[200010];
int fa[200010], ff[200010];
vector<pair<int, pair<int, int> > > edge;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int ffff(int x) { return ff[x] == x ? x : ff[x] = find(ff[x]); }
void dfs(int x, int rt) {
  alive.erase(x);
  fa[x] = rt;
  int cur = 0;
  while (alive.size() && cur < *(--alive.end())) {
    set<int>::iterator it = alive.upper_bound(cur);
    if (from[x].count(*it)) {
      cur = *it;
      continue;
    }
    cur = *it, dfs(cur, rt);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) ff[i] = i;
  for (int j = 0; j < m; j++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    W ^= w, from[x].insert(y), from[y].insert(x),
        edge.push_back(make_pair(w, make_pair(x, y)));
  }
  sort(edge.begin(), edge.end());
  for (int i = 1; i <= n; i++) alive.insert(i);
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    if (alive.count(i)) {
      tot++, dfs(i, i);
    }
  }
  long long ans = 0;
  int minj = 0x3f3f3f3f;
  for (int i = 0; i < m; i++) {
    int x = edge[i].second.first, y = edge[i].second.second, w = edge[i].first;
    if (find(x) == find(y)) {
      if (ffff(x) != ffff(y)) minj = w;
      continue;
    }
    ans += w, fa[find(x)] = find(y), ff[ffff(x)] = ffff(y);
  }
  if (n - tot + m < 1ll * n * (n - 1) / 2)
    printf("%I64d\n", ans);
  else
    printf("%I64d\n", ans + min(minj, W));
  return 0;
}
