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;
template <typename T>
void setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const long long LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int w[1 << 10][1 << 10];
int comp[1 << 10];
int res[1 << 10][1 << 10];
int n, m;
bool has_cycle = 0;
void dfs(int v, int p = -1) {
  for (int i = (0); i < (n); ++i) {
    if (w[v][i]) continue;
    if (i == p || i == v) continue;
    if (comp[i]) {
      assert(comp[i] == comp[v]);
      has_cycle = 1;
      continue;
    }
    comp[i] = comp[v];
    dfs(i, v);
  }
}
int p[1 << 10];
int sz[1 << 10];
int par(int v) {
  if (p[v] == -1) return v;
  return p[v] = par(p[v]);
}
bool unite(int a, int b) {
  a = par(a);
  b = par(b);
  if (a == b) return 0;
  if (sz[a] > sz[b]) swap(a, b);
  sz[b] += sz[a];
  p[a] = b;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  if (n > 1000) {
    cout << 0 << endl;
    return 0;
  }
  int xs = 0;
  for (int i = (0); i < (m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[a][b] = w[b][a] = c;
    xs ^= c;
  }
  int col = 1;
  for (int i = (0); i < (n); ++i) {
    if (comp[i]) continue;
    comp[i] = col++;
    dfs(i);
  }
  if (has_cycle) xs = 0;
  for (int i = (1); i < (col); ++i)
    for (int j = (1); j < (col); ++j) res[i][j] = INF;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j)
      if (comp[i] != comp[j]) {
        if (res[comp[i]][comp[j]] >= w[i][j]) {
          setmin(xs, res[comp[i]][comp[j]]);
          res[comp[i]][comp[j]] = w[i][j];
        } else
          setmin(xs, w[i][j]);
      } else {
        if (w[i][j]) setmin(xs, w[i][j]);
      }
  }
  for (int i = (1); i < (col); ++i) {
    sz[i] = 1;
    p[i] = -1;
  }
  long long ans = 0;
  vector<pair<int, int> > edges;
  for (int i = (1); i < (col); ++i) {
    for (int j = (i + 1); j < (col); ++j) {
      edges.push_back(make_pair(i, j));
    }
  }
  sort(edges.begin(), edges.end(), [&](pair<int, int> a, pair<int, int> b) {
    return res[a.first][a.second] < res[b.first][b.second];
  });
  for (int i = (0); i < ((int)((edges).size())); ++i) {
    if (unite(edges[i].first, edges[i].second))
      ans += res[edges[i].first][edges[i].second];
  }
  cout << ans + xs << endl;
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
