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 inf = 1e9;
const int nax = 2e5 + 20;
map<int, int> g[nax];
void process(int u, set<int> &not_seen,
             priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                            greater<tuple<int, int, int>>> &q) {
  for (int v : not_seen) {
    if (g[u].count(v)) {
      q.push({g[u][v], v, u});
    } else {
      q.push({0, v, u});
    }
  }
}
pair<set<pair<int, int>>, long long> calc_mst(int n) {
  set<int> not_seen;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 greater<tuple<int, int, int>>>
      q;
  int u, v, w;
  for (int i = 0; i < (int)n; ++i) not_seen.insert(i);
  q.push({0, 0, 0});
  set<pair<int, int>> mst;
  long long ans = 0;
  while (((int)q.size()) && ((int)not_seen.size())) {
    tie(w, u, v) = q.top();
    q.pop();
    if (not_seen.count(u)) {
      not_seen.erase(u);
      process(u, not_seen, q);
      if (u > v) swap(u, v);
      mst.insert({u, v});
      ans += w;
    }
  }
  return {mst, ans};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  int n, m;
  cin >> n >> m;
  int u, v, w;
  int sum = 0;
  for (int i = 0; i < (int)m; ++i) {
    cin >> u >> v >> w;
    sum ^= w;
    --u, --v;
    g[u][v] = w;
    g[v][u] = w;
  }
  set<pair<int, int>> mst;
  long long ans;
  tie(mst, ans) = calc_mst(n);
  for (int i = 0; i < n && sum; ++i) {
    for (int j = (int)i + 1; j <= (int)n - 1; ++j) {
      if (!mst.count({i, j}) && !g[i].count(j)) {
        sum = 0;
        break;
      }
    }
  }
  if (sum) {
    for (pair<int, int> e : mst) {
      tie(u, v) = e;
      if (u == v) continue;
      if (!g[u].count(v)) {
        g[u][v] = g[v][u] = sum;
        break;
      }
    }
    tie(mst, ans) = calc_mst(n);
  }
  cout << ans << '\n';
}
