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;
map<int, int> tu[200005];
struct bian {
  int u, v;
};
vector<bian> pai;
bool cmp(bian a, bian b) { return tu[a.u][a.v] < tu[b.u][b.v]; }
set<pair<int, int> > ji;
int bin[200005];
int anc(int x) {
  if (bin[x] == x)
    return x;
  else
    return bin[x] = anc(bin[x]);
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  long long x = 0;
  for (int i = 1; i <= m; i++) {
    int u, v, cc;
    cin >> u >> v >> cc;
    x ^= (long long)cc;
    tu[u][v] = cc;
    tu[v][u] = cc;
  }
  if (n > sqrt(200000) + 1) {
    cout << "0";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      bian temp;
      temp.u = i;
      temp.v = j;
      pai.push_back(temp);
    }
  }
  sort(pai.begin(), pai.end(), cmp);
  for (int i = 0; i < pai.size(); i++) {
    ji.insert(make_pair(tu[pai[i].u][pai[i].v], i));
  }
  long long minn = 1e17;
  for (int i = 0; i < (int)pai.size() && tu[pai[i].u][pai[i].v] == 0; i++) {
    ji.erase(make_pair(0, i));
    ji.insert(make_pair(x, i));
    long long tsum = 0;
    for (int j = 1; j <= n; j++) bin[j] = j;
    for (auto j : ji) {
      int bbb = j.second;
      if (anc(pai[bbb].u) != anc(pai[bbb].v)) {
        bin[anc(pai[bbb].u)] = anc(pai[bbb].v);
        tsum += (long long)j.first;
      }
    }
    minn = min(minn, tsum);
    ji.erase(make_pair(x, i));
    ji.insert(make_pair(0, i));
  }
  cout << minn;
  return 0;
}
