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;
int xo;
int deg[200005];
struct edge {
  int u, v, w;
} ed[200005 + 200005];
bool cmped(edge x, edge y) { return x.w < y.w; }
set<int> nei[200005];
edge ep[200005];
int cnt;
int dsu[200005];
int getdsu(int x) { return dsu[x] == x ? x : dsu[x] = getdsu(dsu[x]); }
long long MST(int ban) {
  long long ans = 0;
  for (int i = 1; i <= n; ++i) dsu[i] = i;
  for (int i = 1; i <= cnt; ++i) {
    if (i == ban) continue;
    int u = getdsu(ep[i].u), v = getdsu(ep[i].v);
    if (u != v) dsu[u] = v;
  }
  if (ban && xo <= ed[1].w) {
    int u = getdsu(ep[ban].u), v = getdsu(ep[ban].v);
    if (u != v) dsu[u] = v, ans += xo;
  }
  for (int i = 1; i <= m; ++i) {
    int u = getdsu(ed[i].u), v = getdsu(ed[i].v);
    if (u != v) dsu[u] = v, ans += ed[i].w;
    if (ban && ed[i].w < xo && (i == m || xo <= ed[i + 1].w)) {
      int u = getdsu(ep[ban].u), v = getdsu(ep[ban].v);
      if (u != v) dsu[u] = v, ans += xo;
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ed[i] = {u, v, w};
    xo ^= w;
    nei[u].insert(v);
    nei[v].insert(u);
    deg[u]++, deg[v]++;
  }
  sort(ed + 1, ed + m + 1, cmped);
  for (int i = 1; i <= n; ++i) dsu[i] = i;
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == n - 1) continue;
    for (int j = 1; j <= n; ++j)
      if (j != i && nei[i].find(j) == nei[i].end()) {
        if (getdsu(i) != getdsu(j)) {
          dsu[getdsu(i)] = getdsu(j);
          ep[++cnt] = {i, j, 0};
        }
        break;
      }
  }
  if (cnt + m < (long long)n * (n - 1) / 2) {
    long long ans = MST(0);
    printf("%lld\n", ans);
    return 0;
  }
  long long ans = LLONG_MAX;
  for (int i = 1; i <= cnt; ++i) ans = min(ans, MST(i));
  printf("%lld\n", ans);
  return 0;
}
