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 uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;
template <typename T>
T abs(T x) {
  return (x < 0) ? (-x) : x;
}
cat gcd(cat a, cat b) {
  if (a > b) swap(a, b);
  while (a) {
    cat c = b % a;
    b = a;
    a = c;
  }
  return b;
}
cat pw(cat a, cat e, cat mod) {
  if (e <= 0) return 1;
  cat x = pw(a, e / 2, mod);
  x = x * x % mod;
  return (e & 1) ? x * a % mod : x;
}
template <typename T>
class fin {
  vector<T> node_val;
  int lastone(int x) { return x & (x ^ (x - 1)); }

 public:
  fin(int N, T init_val) { node_val.resize(N + 10, init_val); }
  void put(int pos, T val) {
    for (int i = pos + 1; i < (int)node_val.size(); i += lastone(i))
      node_val[i] += val;
  }
  T get(int pos) {
    T ret = 0;
    for (int i = pos + 1; i > 0; i -= lastone(i)) ret += node_val[i];
    return ret;
  }
};
template <typename T>
class minfin {
  vector<T> node_val;
  T init_val_;
  int lastone(int x) { return x & (x ^ (x - 1)); }

 public:
  minfin(int N, T init_val) {
    init_val_ = init_val;
    node_val.resize(N + 10, init_val);
  }
  void put(int pos, T val) {
    for (int i = pos + 1; i < (int)node_val.size(); i += lastone(i))
      node_val[i] = min(node_val[i], val);
  }
  T get(int pos) {
    T ret = init_val_;
    for (int i = pos + 1; i > 0; i -= lastone(i)) ret = min(ret, node_val[i]);
    return ret;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int> > > G(N);
  cat x = 0;
  for (int i = 0; i < M; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[--u].push_back({--v, w});
    G[v].push_back({u, w});
    x ^= w;
  }
  vector<int> in_ucomp(N, -1);
  vector<vector<int> > ucomp(N);
  int nc = 0;
  vector<int> fr(N);
  for (int i = 0; i < N; i++) fr.push_back(i);
  vector<char> bl(N, 0);
  for (int r = 0; r < N; r++)
    if (in_ucomp[r] == -1) {
      in_ucomp[r] = nc;
      static queue<int> q;
      q.push(r);
      while (!q.empty()) {
        for (auto p : G[q.front()]) bl[p.first] = 1;
        for (int i = 0; i < (int)fr.size(); i++) {
          if (bl[fr[i]]) continue;
          if (in_ucomp[fr[i]] == -1) {
            in_ucomp[fr[i]] = nc;
            q.push(fr[i]);
          }
          swap(fr.back(), fr[i]);
          fr.pop_back();
          i--;
        }
        for (auto p : G[q.front()]) bl[p.first] = 0;
        q.pop();
      }
      nc++;
    }
  vector<vector<pair<int, int> > > Gc(nc);
  for (int i = 0; i < N; i++)
    for (auto p : G[i])
      if (in_ucomp[i] != in_ucomp[p.first]) {
        Gc[in_ucomp[i]].push_back({in_ucomp[p.first], p.second});
        Gc[in_ucomp[p.first]].push_back({in_ucomp[i], p.second});
      }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  vector<char> used(nc, 0);
  used[0] = 1;
  for (auto p : Gc[0]) q.push({p.second, p.first});
  cat ans0 = 0;
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    if (used[p.second]) continue;
    used[p.second] = 1;
    ans0 += p.first;
    for (auto r : Gc[p.second])
      if (!used[r.first]) q.push({r.second, r.first});
  }
  if (nc != N - (1LL * N * (N - 1) / 2 - M)) {
    cout << ans0 << "\n";
    return 0;
  }
  int M_fr = N - nc;
  used = vector<char>(nc, 0);
  vector<char> usedv(N, 0);
  used[in_ucomp[0]] = usedv[0] = 1;
  for (auto p : G[0]) q.push({p.second, p.first});
  for (auto v : ucomp[in_ucomp[0]]) q.push({x, v});
  cat ans1 = 0;
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    if (usedv[p.second]) continue;
    usedv[p.second] = 1;
    ans1 += p.first;
    for (auto r : G[p.second])
      if (!usedv[r.first]) q.push({r.second, r.first});
    if (!used[in_ucomp[p.second]]) {
      used[in_ucomp[p.second]] = 1;
      for (auto v : ucomp[in_ucomp[p.second]])
        if (!usedv[v]) q.push({x, v});
    }
  }
  cout << min(ans0 + x, ans1 - x * (M_fr - 1)) << "\n";
}
