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;
struct P {
  int x, y;
  bool operator<(const P &p) {
    if (x != p.x)
      return x < p.x;
    else
      return y < p.y;
  }
};
long long getMSTCount(int n, vector<pair<long long, pair<int, int> > > &ws,
                      set<pair<int, int> > &edges) {
  vector<vector<int> > parts;
  vector<int> partVal(n, -1);
  long long mst = 0;
  bool done = false;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= n - 1; ++j) {
      int pvi = partVal[i];
      int pvj = partVal[j];
      if (edges.find(make_pair(i, j)) == edges.end()) {
        int curpart = parts.size();
        if (pvi == -1 && pvj == -1) {
          partVal[i] = curpart;
          partVal[j] = curpart;
          parts.push_back(vector<int>());
          parts[curpart].push_back(i);
          parts[curpart].push_back(j);
          if (parts[curpart].size() == n) {
            done = true;
          }
        } else if (pvi == -1) {
          partVal[i] = partVal[j];
          parts[partVal[j]].push_back(i);
          if (parts[partVal[j]].size() == n) {
            done = true;
          }
        } else if (pvj == -1) {
          partVal[j] = partVal[i];
          parts[partVal[i]].push_back(j);
          if (parts[partVal[i]].size() == n) {
            done = true;
          }
        } else if (pvi != pvj) {
          if (parts[pvi].size() < parts[pvj].size()) {
            for (int k = 0; k < parts[pvi].size(); ++k) {
              partVal[parts[pvi][k]] = pvj;
              parts[pvj].push_back(parts[pvi][k]);
            }
            if (parts[pvj].size() == n) {
              done = true;
            }
            parts[pvi].clear();
          } else {
            for (int k = 0; k < parts[pvj].size(); ++k) {
              partVal[parts[pvj][k]] = pvi;
              parts[pvi].push_back(parts[pvj][k]);
            }
            if (parts[pvi].size() == n) {
              done = true;
            }
            parts[pvj].clear();
          }
        }
      }
      if (done) {
        break;
      }
    }
    if (done) {
      break;
    }
  }
  for (int k = 0; k < ws.size(); ++k) {
    if (done) {
      break;
    }
    int curpart = parts.size();
    int i = ws[k].second.first;
    int j = ws[k].second.second;
    int pvi = partVal[i];
    int pvj = partVal[j];
    if (partVal[i] == -1 && partVal[j] == -1) {
      mst += ws[k].first;
      partVal[i] = curpart;
      partVal[j] = curpart;
      parts.push_back(vector<int>());
      parts[curpart].push_back(i);
      parts[curpart].push_back(j);
      if (parts[curpart].size() == n) {
        done = true;
      }
    } else if (partVal[i] == -1) {
      mst += ws[k].first;
      partVal[i] = partVal[j];
      parts[partVal[j]].push_back(i);
      if (parts[partVal[j]].size()) {
        done = true;
      }
    } else if (partVal[j] == -1) {
      mst += ws[k].first;
      partVal[j] = partVal[i];
      parts[partVal[i]].push_back(j);
      if (parts[partVal[i]].size()) {
        done = true;
      }
    } else if (pvi != pvj) {
      mst += ws[k].first;
      if (parts[pvi].size() < parts[pvj].size()) {
        for (int k = 0; k < parts[pvi].size(); ++k) {
          partVal[parts[pvi][k]] = pvj;
          parts[pvj].push_back(parts[pvi][k]);
        }
        if (parts[pvj].size() == n) {
          done = true;
        }
        parts[pvi].clear();
      } else {
        for (int k = 0; k < parts[pvj].size(); ++k) {
          partVal[parts[pvj][k]] = pvi;
          parts[pvi].push_back(parts[pvj][k]);
        }
        if (parts[pvi].size() == n) {
          done = true;
        }
        parts[pvj].clear();
      }
    }
  }
  return mst;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, pair<int, int> > > ws;
  set<pair<int, int> > edges;
  long long a;
  int b, c;
  long long x = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> c;
    ws.push_back(make_pair(c, make_pair(a - 1, b - 1)));
    edges.insert(make_pair(a - 1, b - 1));
    edges.insert(make_pair(b - 1, a - 1));
    x ^= c;
  }
  long long mst = 1e18;
  sort(ws.begin(), ws.end());
  if (n < 500) {
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j <= n - 1; ++j) {
        if (edges.find(make_pair(i, j)) == edges.end()) {
          edges.insert(make_pair(i, j));
          edges.insert(make_pair(j, i));
          vector<pair<long long, pair<int, int> > > wscp = ws;
          wscp.push_back(make_pair(x, make_pair(i, j)));
          sort(wscp.begin(), wscp.end());
          mst = min(mst, getMSTCount(n, wscp, edges));
          edges.erase(make_pair(i, j));
          edges.erase(make_pair(j, i));
        }
      }
    }
  } else {
    mst = getMSTCount(n, ws, edges);
  }
  cout << mst << endl;
  return 0;
}
