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 <class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p) {
  return out << '(' << p.first << ',' << p.second << ')';
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  return in >> p.first >> p.second;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (T& x : v) in >> x;
  return in;
}
ostream& operator<<(ostream& out, const vector<string>& v) {
  for (const string& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T>>& v) {
  for (const vector<T>& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  for (const T& x : v) out << x << ' ';
  return out;
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
const int h = 1000000007;
class DSU {
 private:
  vector<int> par, size;
  int distinct_sets_count;

 public:
  DSU(int n) {
    distinct_sets_count = n;
    par.resize(n);
    for (int i = 0; i < n; i++) par[i] = i;
    size.resize(n, 1);
  }
  int root(const int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void connect(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) swap(a, b);
    size[a] += size[b];
    par[b] = a;
    distinct_sets_count--;
  }
  bool same_component(const int x, const int y) { return root(x) == root(y); }
  bool is_leader(const int x) { return root(x) == x; }
  int size_of_component(const int x) { return size[root(x)]; }
  int count() const { return distinct_sets_count; }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cerr.setstate(ios::failbit);
  ll n, m;
  cin >> n >> m;
  int xr = 0;
  vector<map<int, int>> v(n);
  DSU dsu(n);
  vector<pair<int, pii>> edges(n);
  for (int i = (0); i < (m); i++) {
    int x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    xr ^= w;
    v[x][y] = w;
    v[y][x] = w;
    edges.push_back(make_pair(w, make_pair(x, y)));
  }
  sort(edges.begin(), edges.end());
  set<int> to_check;
  for (int i = (0); i < (n); i++) to_check.insert(i);
  for (int i = (0); i < (n); i++) {
    if (!to_check.count(i)) continue;
    stack<int> st;
    st.push(i);
    to_check.erase(i);
    while (!st.empty()) {
      int x = st.top();
      st.pop();
      vi z;
      for (int c : to_check) {
        if (!v[x].count(c)) {
          dsu.connect(x, c);
          z.push_back(c);
          st.push(c);
        }
      }
      for (int y : z) to_check.erase(y);
    }
  }
  bool remove = n * (n - 1) / 2 - m != n - dsu.count();
  ll ans = xr;
  DSU dsu2(n);
  for (auto p : edges) {
    if (!dsu.same_component(p.second.first, p.second.second)) {
      dsu.connect(p.second.first, p.second.second);
      dsu2.connect(p.second.first, p.second.second);
      ans += p.first;
    } else if (!dsu2.same_component(p.second.first, p.second.second) and
               p.first <= xr) {
      remove = true;
      ans += p.first;
    }
  }
  if (remove) ans -= xr;
  cout << ans;
}
