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 long long N = 2e5 + 5, oo = 1e9;
long long n, k, ts, lab[N], sum, cnt, rs, cl;
vector<pair<long, pair<long, long> > > ed;
long long root(long long first) {
  return lab[first] < 0 ? first : lab[first] = root(lab[first]);
}
void dsu(long long u, long long v) {
  u = root(u);
  v = root(v);
  if (lab[u] < lab[v]) swap(u, v);
  lab[u] += lab[v];
  lab[v] = u;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    ts ^= w;
    ed.push_back(make_pair(w, make_pair(u, v)));
  }
  cl = n * (n - 1) / 2 - k;
  sort(ed.begin(), ed.end());
  for (long long i = 1; i <= n; i++) lab[i] = -1;
  sum = 0;
  cnt = 0;
  rs = oo;
  if (cl > n - 1) rs = 0;
  if (cl == n - 1) rs = ts;
  for (pair<long, pair<long, long> > canh : ed) {
    long long u = canh.second.first, v = canh.second.second;
    if (root(u) != root(v)) {
      dsu(u, v);
      sum += canh.first;
      cnt++;
      if (cnt > n - 1) break;
      if (n - 1 - cnt < cl) rs = min(rs, sum);
      if (n - 1 - cnt == cl) rs = min(rs, sum + ts);
    }
  }
  cout << rs << '\n';
  return 0;
}
