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 MAXN = 400010;
struct EG {
  int x, y, z;
} e[MAXN];
int n, m, x, y, z, flg, xr, hd, pre[MAXN], nxt[MAXN], f[MAXN], ff[MAXN],
    vis[MAXN];
set<pair<int, int> > bb;
long long ans;
bool cmp(EG a, EG b) { return a.z < b.z; }
int findr(int x) { return (f[x] == x ? x : f[x] = findr(f[x])); }
int findr2(int x) { return (ff[x] == x ? x : ff[x] = findr(ff[x])); }
void del(int x) {
  int p = pre[x], n = nxt[x];
  if (hd == x) {
    hd = n;
  }
  nxt[p] = n, pre[n] = p;
  return;
}
void dfs(int x, int fa) {
  vis[x] = 1;
  for (int i = 1; i <= n; i++) {
    if (i == fa) {
      continue;
    }
    if (bb.find(make_pair(x, i)) == bb.end() && i != x) {
      if (vis[i]) {
        flg = 0;
        return;
      }
      dfs(i, x);
    }
  }
  return;
}
void chkflg() {
  flg = 1;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, 0);
    }
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    f[i] = ff[i] = i;
  }
  for (int i = 1; i < n; i++) {
    pre[i + 1] = i, nxt[i] = i + 1;
  }
  hd = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    bb.insert(make_pair(e[i].x, e[i].y));
    bb.insert(make_pair(e[i].y, e[i].x));
    xr ^= e[i].z;
  }
  queue<int> q;
  for (int i = hd; i; i = hd) {
    int tmp = i;
    del(i);
    q.push(i);
    while (!q.empty()) {
      int a = q.front();
      q.pop();
      f[a] = tmp;
      for (int j = hd; j; j = nxt[j]) {
        if (bb.find(make_pair(a, j)) == bb.end()) {
          del(j);
          q.push(j);
        }
      }
    }
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int fx = findr(e[i].x), fy = findr(e[i].y);
    int ffx = findr2(e[i].x), ffy = findr2(e[i].y);
    if (fx != fy) {
      ans += e[i].z;
      f[fx] = fy;
      ff[ffx] = ffy;
    } else {
      if (flg) {
        ans += min(e[i].z, xr);
        flg = 0;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
