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 N = (int)2e5 + 100;
int u[N], v[N];
int w[N];
set<int> vis;
set<int> E[N];
vector<int> T[N];
int par[N];
struct edge {
  int u;
  int v;
  long long wei;
  bool operator<(const edge &ee) const { return wei < ee.wei; }
};
int fin(int x) {
  if (x == par[x]) return x;
  return par[x] = fin(par[x]);
}
bool unite(int a, int b) {
  a = fin(a);
  b = fin(b);
  if (a == b) return false;
  par[a] = b;
  return true;
}
void dfs(int u) {
  int las = 0;
  int nex;
  for (auto x : E[u]) {
    while (1) {
      auto it = vis.upper_bound(las);
      if (it == vis.end() || *it >= x) break;
      nex = *it;
      vis.erase(it);
      T[u].push_back(nex);
      T[nex].push_back(u);
      unite(u, nex);
      dfs(nex);
    }
    las = x;
  }
  while (1) {
    auto it = vis.upper_bound(las);
    if (it == vis.end()) break;
    nex = *it;
    vis.erase(it);
    T[u].push_back(nex);
    T[nex].push_back(u);
    unite(u, nex);
    dfs(nex);
  }
}
bool has[1005][1005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<edge> lis;
  int xor_sum = 0;
  for (int i = 1; i <= m; i++) {
    cin >> u[i] >> v[i] >> w[i];
    E[u[i]].insert(v[i]);
    E[v[i]].insert(u[i]);
    lis.push_back({u[i], v[i], w[i]});
    xor_sum ^= w[i];
  }
  sort(lis.begin(), lis.end());
  for (int i = 1; i <= n; i++) {
    vis.insert(i);
    par[i] = i;
  }
  int node;
  while (!vis.empty()) {
    auto it = vis.begin();
    node = *it;
    vis.erase(it);
    dfs(node);
  }
  long long soln = 0;
  long long low = (long long)4e9;
  if (n <= 1000) {
    for (int i = 1; i <= m; i++) {
      has[u[i]][v[i]] = true;
      has[v[i]][u[i]] = true;
      if (fin(u[i]) == fin(v[i])) {
        low = min(low, (long long)w[i]);
      }
    }
    for (int i = 1; i <= n; i++) {
      for (auto x : T[i]) {
        has[i][x] = true;
        has[x][i] = true;
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (!has[i][j] && fin(i) == fin(j)) low = 0;
      }
    }
  } else {
    low = 0;
  }
  for (auto ei : lis) {
    if (unite(ei.u, ei.v)) {
      soln += ei.wei;
    }
  }
  soln += min(low, (long long)xor_sum);
  cout << soln << "\n";
  return 0;
}
