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;
template <class T>
inline T mymin(T x, T y) {
  return x < y ? x : y;
}
template <class T>
inline T mymax(T x, T y) {
  return x > y ? x : y;
}
template <class T>
inline void zwap(T &x, T &y) {
  x ^= y ^= x ^= y;
}
int n, m;
int s1[210000], t1, s2[210000], t2;
long long dis[210000];
bool v[210000];
struct node {
  int y, next;
  long long k;
  bool v;
} a[410000];
int len = 1, last[210000];
inline void ins(int x, int y, long long k) {
  len++;
  a[len].y = y;
  a[len].k = k;
  a[len].next = last[x];
  last[x] = len;
}
long long ans = 0, res = 0, used;
int be[210000], becnt = 0;
void dfs(int x) {
  be[x] = becnt;
  for (int k = last[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (a[k].v && !be[y]) dfs(y);
  }
}
int main() {
  long long shit = 0;
  scanf("%d%d", &n, &m);
  res = (long long)n * (n - 1) / 2 - (long long)m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long k;
    scanf("%d%d%lld", &x, &y, &k);
    ins(x, y, k);
    ins(y, x, k);
    shit ^= k;
  }
  for (int k = last[1]; k; k = a[k].next) dis[a[k].y] = k;
  for (int i = 2; i <= n; i++) {
    if (dis[i])
      s1[++t1] = i;
    else
      s2[++t2] = i;
  }
  for (int i = 2; i <= n; i++) {
    int x = 0;
    if (t2)
      x = s2[t2--], used++;
    else {
      x = 1;
      for (int j = 2; j <= t1; j++) {
        if (a[dis[s1[x]]].k > a[dis[s1[j]]].k) x = j;
      }
      if (x != t1) zwap(s1[x], s1[t1]);
      x = s1[t1];
      t1--;
      ans += a[dis[x]].k;
      a[dis[x]].v = a[dis[x] ^ 1].v = 1;
    }
    for (int k = last[x]; k; k = a[k].next) {
      v[a[k].y] = 1;
      if (dis[a[k].y] && a[dis[a[k].y]].k > a[k].k) dis[a[k].y] = k;
    }
    for (int j = 1; j <= t1; j++) {
      if (!v[s1[j]]) {
        s2[++t2] = s1[j];
        if (j != t1) zwap(s1[j], s1[t1]);
        t1--;
        j--;
      }
    }
    for (int k = last[x]; k; k = a[k].next) v[a[k].y] = 0;
  }
  if (used == res) {
    long long sum = ans;
    ans += shit;
    for (int i = 1; i <= n; i++) {
      if (!be[i]) becnt++, dfs(i);
    }
    for (int i = 1; i <= n; i++) {
      for (int k = last[i]; k; k = a[k].next) {
        if (!a[k].v && a[k].k < shit) {
          if (be[i] != be[a[k].y]) ans = mymin(ans, sum + (k - a[k].k));
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
