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;
long long inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
long long chkmin(T &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
long long chkmax(T &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T, class T2>
T mmin(T a, T2 b) {
  return a < b ? a : b;
}
template <class T, class T2>
T mmax(T a, T2 b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
long long dcmp(T a, T b) {
  return a > b;
}
template <long long *a>
long long cmp_a(long long first, long long second) {
  return a[first] < a[second];
}
template <class T>
bool sort2(T &a, T &b) {
  return a > b ? swap(a, b), 1 : 0;
}
struct __INIT__ {
  __INIT__() {
    fill((unsigned char *)&inf, (unsigned char *)&inf + sizeof(inf), 0x3f);
  }
} __INIT___;
namespace io {
const long long SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
long long f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r' || *first == EOF))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
long long xu[200005], xv[200005], xw[200005];
vector<long long> to[200005];
set<long long> ts[200005], st;
long long fa[200005];
long long q[200005], *l, *r;
void bfs(long long v) {
  *(l = r = q) = v;
  st.erase(v);
  fa[v] = v;
  for (; l <= r; ++l) {
    long long first = *l;
    for (set<long long>::iterator it = st.begin(); it != st.end();) {
      if (ts[first].count(*it)) {
        ++it;
        continue;
      } else {
        auto nw = it;
        ++nw;
        *(++r) = *it;
        fa[*it] = v;
        st.erase(it);
        it = nw;
      }
    }
  }
}
long long find(long long first) {
  return first == fa[first] ? first : fa[first] = find(fa[first]);
}
struct edge {
  long long u, v, w;
};
edge e[200005];
bool operator<(const edge &a, const edge &b) { return a.w < b.w; }
signed main() {
  long long n, m;
  read(n, m);
  long long rem = n >= 1000 ? inf : n * (n - 1) / 2 - m;
  long long s = 0;
  for (long long i = 1; i <= m; ++i) {
    read(e[i].u, e[i].v, e[i].w);
    s ^= e[i].w;
    long long u = e[i].u, v = e[i].v;
    to[u].emplace_back(v);
    to[v].emplace_back(u);
    ts[u].insert(v);
    ts[v].insert(u);
  }
  sort(e + 1, e + m + 1);
  for (long long i = 1; i <= n; ++i) st.insert(i);
  long long l = n;
  for (long long i = 1; i <= n; ++i) {
    if (st.count(i)) {
      bfs(i);
      --l;
    }
  }
  long long xs = inf;
  for (long long i = 1; i <= m; ++i)
    if (find(e[i].u) == find(e[i].v)) {
      chkmin(xs, e[i].w);
    }
  long long sa = 0;
  for (long long i = 1; i <= m; ++i) {
    if (find(e[i].u) != find(e[i].v)) {
      sa += e[i].w;
      fa[find(e[i].v)] = find(e[i].u);
    }
  }
  if (l < rem) return write(sa, '\n');
  return write(sa + mmin(s, xs), '\n');
  return 0;
}
