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 long long maxn = 2e5 + 100;
long long read() {
  long long ans = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' or ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    ans = (ans << 1) + (ans << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? ~ans + 1 : ans;
}
long long n, m, u, v, w, vis[maxn], tot, cnt, fa[maxn], ans;
map<pair<long long, long long>, bool> mmp;
set<long long> s;
struct sd {
  long long to, val;
};
struct node {
  long long u, v, w;
} e[maxn];
vector<sd> g[maxn];
bool cmp(sd a, sd b) { return a.val < b.val; }
bool cmp1(node a, node b) { return a.w < b.w; }
long long find(long long x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void bfs(long long x) {
  queue<long long> q;
  q.push(x);
  s.erase(s.find(x));
  vis[x] = 1;
  while (!q.empty()) {
    long long now = q.front();
    q.pop();
    for (auto to : s)
      if (!mmp[make_pair(to, now)])
        q.push(to), vis[to] = 1, s.erase(s.find(to)), fa[to] = x;
  }
}
int main() {
  n = read(), m = read();
  for (long long i = 1; i <= m; ++i) {
    u = read(), v = read(), w = read();
    tot ^= w;
    g[u].push_back((sd){v, w});
    g[v].push_back((sd){u, w});
    e[++cnt] = (node){u, v, w};
    mmp[make_pair(u, v)] = mmp[make_pair(v, u)] = 1;
  }
  sort(e + 1, e + 1 + cnt, cmp1);
  bool ok = 0;
  for (long long i = 1; i <= n; ++i) {
    fa[i] = i;
    s.insert(i);
    sort(g[i].begin(), g[i].end(), cmp);
    if (g[i].size() < n - 2) ok = 1;
  }
  if (!ok) {
    long long nowcnt = 0, nowtot = 0;
    for (long long i = 1; i <= m; ++i) {
      long long x = e[i].u, y = e[i].v;
      if (find(x) != find(y)) {
        nowcnt++;
        if (nowcnt == n * (n - 1) / 2 - m) nowtot = e[i].w;
        if (nowcnt >= n * (n - 1) / 2 - m) ans += e[i].w;
        fa[find(x)] = find(y);
      }
    }
    ans = min(ans, ans - nowtot + tot);
    printf("%lld\n", ans);
  } else {
    for (long long i = 1; i <= n; ++i)
      if (!vis[i]) bfs(i);
    for (long long i = 1; i <= m; ++i) {
      long long x = e[i].u, y = e[i].v;
      if (find(x) != find(y)) {
        ans += e[i].w;
        fa[find(x)] = find(y);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
