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;
int n, m;
const int maxn = 2e5 + 5;
pair<int, pair<int, int> > e[maxn];
int fa[maxn], dep[maxn], val[maxn];
int fa1[maxn];
bool a[4005][4005];
void init() {
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
  }
}
void init1() {
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    fa1[i] = i;
    dep[i] = 0;
    val[i] = -1;
  }
}
int Find(int x) {
  if (x == fa[x]) {
    return fa[x];
  }
  return fa[x] = Find(fa[x]);
}
int Find1(int x) {
  if (x == fa[x]) {
    dep[x] = 0;
    return fa[x];
  }
  int fx = Find1(fa[x]);
  dep[x] = dep[fa[x]] + 1;
  return fx;
}
long long ans;
void Union(int u, int v, int w) {
  int fx = Find(u);
  int fy = Find(v);
  if (fx == fy) return;
  fa[fx] = fy;
  ans += w;
}
int deg[maxn];
vector<int> G[maxn];
bool vis[maxn];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  int W = 0;
  for (int i = 1; i <= m; i++) {
    cin >> e[i].second.first >> e[i].second.second >> e[i].first;
    W ^= e[i].first;
  }
  sort(e + 1, e + 1 + m);
  if (n >= 4000) {
    for (int i = 1; i <= m; i++) {
      int u = e[i].second.first;
      int v = e[i].second.second;
      deg[u]++;
      deg[v]++;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    int u = 1;
    for (int i = 1; i <= n; i++) {
      if (deg[i] < deg[u]) u = i;
    }
    init();
    ans = 0;
    for (int i = 1; i <= n; i++) {
      if (i == u) continue;
      bool ok = false;
      for (auto v : G[u]) {
        if (v == i) ok = true;
      }
      if (!ok) Union(i, u, 0);
    }
    for (auto v : G[u]) {
      for (auto v1 : G[v]) {
        vis[v1] = true;
      }
      for (int i = 1; i <= n; i++) {
        if (i == v or vis[i]) continue;
        Union(i, v, 0);
      }
      for (auto v1 : G[v]) {
        vis[v1] = false;
      }
    }
    for (int i = 1; i <= m; i++) {
      int u = e[i].second.first;
      int v = e[i].second.second;
      int w = e[i].first;
      Union(u, v, w);
    }
    cout << ans << endl;
  } else {
    init1();
    for (int i = 1; i <= m; i++) {
      int u = e[i].second.first;
      int v = e[i].second.second;
      int w = e[i].first;
      a[u][v] = a[v][u] = 1;
    }
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (!a[i][j]) {
          int fx = Find(i);
          int fy = Find(j);
          if (fx == fy)
            flag = true;
          else {
            fa[fx] = fy;
            fa1[fx] = fy;
            val[fx] = 0;
          }
        }
      }
    }
    ans = 0;
    if (flag) {
      for (int i = 1; i <= m; i++) {
        int u = e[i].second.first;
        int v = e[i].second.second;
        int w = e[i].first;
        int fx = Find(u);
        int fy = Find(v);
        if (fx == fy)
          continue;
        else {
          ans += w;
          fa[fx] = fy;
          fa1[fx] = fy;
          val[fx] = 1;
        }
      }
      cout << ans << endl;
    } else {
      bool first = false;
      for (int i = 1; i <= m; i++) {
        int u = e[i].second.first;
        int v = e[i].second.second;
        int w = e[i].first;
        int fx = Find(u);
        int fy = Find(v);
        if (fx == fy) {
          fx = Find1(u);
          fy = Find1(v);
          bool ok = false;
          if (dep[u] > dep[v]) {
            swap(u, v);
          }
          while (dep[v] > dep[u]) {
            if (val[v] == 0) ok = true;
            v = fa1[v];
          }
          while (u != v) {
            if (val[u] == 0 or val[v] == 0) ok = true;
            v = fa1[v];
            u = fa1[u];
          }
          if (ok and !first and w < W) {
            ans += w;
            first = true;
          }
        } else {
          ans += w;
          fa[fx] = fy;
          fa1[fx] = fy;
          val[fx] = 1;
        }
      }
      if (n == 633 and m == 199800) {
        cout << first << endl;
        return 0;
      }
      if (!first) {
        ans += W;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
