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 MAXN = 2E5;
tuple<int, int, int> edges[MAXN];
vector<pair<int, int>> adjList[MAXN + 1];
bool visited[MAXN + 1];
int par[MAXN + 1];
int sz[MAXN + 1];
bool neigh[MAXN + 1];
set<int> looking;
int getRoot(int x) {
  if (par[x] != x) par[x] = getRoot(par[x]);
  return par[x];
}
void mge(int x, int y) {
  x = getRoot(x);
  y = getRoot(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  par[y] = x;
  sz[x] += sz[y];
}
int dfs(int v) {
  int ans = 0;
  visited[v] = true;
  for (pair<int, int> edge : adjList[v]) {
    neigh[edge.first] = true;
  }
  vector<int> vec;
  for (int x : looking) {
    if (neigh[x]) continue;
    ans++;
    vec.push_back(x);
    mge(x, v);
  }
  for (int x : vec) looking.erase(looking.find(x));
  for (pair<int, int> edge : adjList[v]) {
    neigh[edge.first] = false;
  }
  for (int adj : vec) {
    if (!visited[adj]) ans += dfs(adj);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    sz[i] = 1;
    par[i] = i;
  }
  int x = 0;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adjList[u].push_back({v, w});
    adjList[v].push_back({u, w});
    edges[i] = {w, u, v};
    x ^= w;
  }
  long long totalEdges = (long long)n * (n - 1) / 2;
  int cnt = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      looking.clear();
      for (int j = 1; j <= n; j++) {
        if (!visited[j] && j != i) looking.insert(j);
      }
      cnt += dfs(i);
    }
  }
  sort(edges, edges + m);
  for (int i = 0; i < m; i++) {
    int u = get<1>(edges[i]);
    int v = get<2>(edges[i]);
    if (getRoot(u) == getRoot(v)) continue;
    ans += get<0>(edges[i]);
    mge(u, v);
  }
  if (cnt + m == totalEdges) ans += x;
  cout << ans << "\n";
  return 0;
}
