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;
vector<int> G[200005];
int T[710][710];
int n, m, u[200005], v[200005];
long long w[200005], res;
int id[200005], flag;
int fa[200005];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
inline int cmp(int x, int y) { return w[x] < w[y]; }
int d[200005];
inline int cmp2(int x, int y) { return d[x] < d[y]; }
inline void unite(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) fa[fx] = fy;
}
void solve1() {
  for (int i = 1; i <= m; i++) T[u[i]][v[i]] = T[v[i]][u[i]] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (!T[i][j]) {
        int fx = find(i), fy = find(j);
        if (fx != fy)
          fa[fx] = fy;
        else
          flag = 1;
      }
    }
  }
}
int tmp[200005];
void solve2() {
  while (1) {
  }
  flag = 1;
  for (int i = 1; i <= m; i++) {
    d[u[i]]++, d[v[i]]++;
    G[u[i]].push_back(v[i]);
    G[v[i]].push_back(u[i]);
  }
  for (int i = 1; i <= n; i++) id[i] = i;
  sort(id + 1, id + n + 1, cmp2);
  for (int i = 0; i < G[id[1]].size(); i++) {
    tmp[G[id[1]][i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (!tmp[i]) fa[i] = id[1];
  }
  for (int i = 1; i <= n; i++) {
    if (find(i) != id[1]) {
      memset(tmp, 0, sizeof(tmp));
      for (int j = 0; j < G[i].size(); j++) {
        tmp[G[i][j]] = 1;
      }
      for (int j = 1; j <= n; j++) {
        if (!tmp[j]) unite(i, j);
      }
    }
  }
}
int type[200005];
int fa2[200005];
int find2(int x) { return x == fa2[x] ? x : fa2[x] = find(fa2[x]); }
void unite2(int x, int y) {
  int fx = find2(x), fy = find2(y);
  if (fx != fy) fa2[fx] = fy;
}
int used[200005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", &u[i], &v[i], &w[i]);
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  if (n < 700)
    solve1();
  else
    solve2();
  long long mn = 0;
  if (!flag) {
    for (int i = 1; i <= m; i++) mn ^= w[i];
  }
  for (int i = 1; i <= n; i++) type[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (fa[i] == i) type[i] = 1;
  }
  for (int i = 1; i <= m; i++) id[i] = i;
  sort(id + 1, id + m + 1, cmp);
  for (int i = 1; i <= n; i++) {
    fa2[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    int fx = find(u[id[i]]), fy = find(v[id[i]]);
    if (fx != fy) {
      if (type[u[id[i]]] || type[v[id[i]]]) unite2(u[id[i]], v[id[i]]);
      res += w[id[i]];
      fa[fx] = fy;
      used[i] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (used[i]) continue;
    int fx = find2(u[id[i]]), fy = find2(v[id[i]]);
    if (fx != fy) mn = min(mn, w[id[i]]);
  }
  if (!flag) res += mn;
  printf("%lld", res);
  return 0;
}
