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;
const int MAXN = 200005;
const int MAXINT = 1073741823;
vector<int> neighbors[MAXN];
set<int> free_neighbors[MAXN];
set<pair<int, pair<int, int>>> edges_1;
set<pair<int, pair<int, int>>> free_edges;
vector<pair<int, pair<int, int>>> edges_2;
vector<int> to_check;
bitset<MAXN> visited;
int size_of[MAXN], parent_of[MAXN];
bool check_cycle(int v, int parent) {
  bool result = false;
  visited[v] = true;
  for (int i : free_neighbors[v])
    if (!visited[i])
      result |= check_cycle(i, v);
    else if (i != parent)
      return true;
  return result;
}
bool comparison(int x, int y) {
  return neighbors[x].size() < neighbors[y].size();
}
int root(int v) {
  return (v == parent_of[v] ? v : parent_of[v] = root(parent_of[v]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, u, v, w, total_xor = 0, answer = 0, current_answer, current, x;
  bool cycle_exists;
  cin >> n >> m;
  if (n <= 640) {
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        free_neighbors[i].insert(j);
        free_neighbors[j].insert(i);
        edges_1.emplace(0, make_pair(i, j));
        free_edges.emplace(0, make_pair(i, j));
      }
    for (int i = 0; i < m; i++) {
      cin >> u >> v >> w;
      u--;
      v--;
      if (u > v) swap(u, v);
      free_neighbors[u].erase(v);
      free_neighbors[v].erase(u);
      edges_1.erase(make_pair(0, make_pair(u, v)));
      edges_1.insert(make_pair(w, make_pair(u, v)));
      free_edges.erase(make_pair(0, make_pair(u, v)));
      total_xor ^= w;
    }
    for (int i = 0; i < n; i++)
      if (!visited[i] && !cycle_exists) cycle_exists = check_cycle(i, -1);
    if (cycle_exists) {
      for (int i = 0; i < n; i++) {
        parent_of[i] = i;
        size_of[i] = 1;
      }
      for (pair<int, pair<int, int>> i : edges_1) {
        tie(u, v) = i.second;
        u = root(u);
        v = root(v);
        if (u == v) continue;
        if (size_of[u] < size_of[v]) swap(u, v);
        size_of[u] += size_of[v];
        parent_of[v] = u;
        size_of[v] = 0;
        answer += i.first;
      }
      cout << answer;
      return 0;
    }
    answer = MAXINT;
    for (pair<int, pair<int, int>> k : free_edges) {
      current_answer = 0;
      edges_1.erase(k);
      edges_1.emplace(total_xor, k.second);
      for (int i = 0; i < n; i++) {
        parent_of[i] = i;
        size_of[i] = 1;
      }
      for (pair<int, pair<int, int>> i : edges_1) {
        if (i == k) continue;
        tie(u, v) = i.second;
        u = root(u);
        v = root(v);
        if (u == v) continue;
        if (size_of[u] < size_of[v]) swap(u, v);
        size_of[u] += size_of[v];
        parent_of[v] = u;
        size_of[v] = 0;
        current_answer += i.first;
      }
      edges_1.erase(make_pair(total_xor, k.second));
      edges_1.insert(k);
      answer = min(answer, current_answer);
    }
    cout << answer;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    u--;
    v--;
    neighbors[u].push_back(v);
    neighbors[v].push_back(u);
    edges_2.emplace_back(w, make_pair(u, v));
  }
  for (int i = 0; i < n; i++) to_check.push_back(i);
  for (int i = 0; i < n; i++) {
    parent_of[i] = i;
    size_of[i] = 1;
  }
  sort(to_check.begin(), to_check.end(), comparison);
  for (int i : to_check) {
    if (visited[i]) continue;
    visited[i] = true;
    current = 0;
    x = 0;
    while (current < n) {
      if (x < neighbors[i].size() && neighbors[i][x] == current)
        x++;
      else {
        u = i;
        v = current;
        u = root(u);
        v = root(v);
        if (u != v) {
          if (size_of[u] < size_of[v]) swap(u, v);
          size_of[u] += size_of[v];
          parent_of[v] = u;
          size_of[v] = 0;
          visited[current] = true;
        }
      }
      current++;
    }
  }
  sort(edges_2.begin(), edges_2.end());
  for (pair<int, pair<int, int>> i : edges_2) {
    tie(u, v) = i.second;
    u = root(u);
    v = root(v);
    if (u == v) continue;
    if (size_of[u] < size_of[v]) swap(u, v);
    size_of[u] += size_of[v];
    parent_of[v] = u;
    size_of[v] = 0;
    answer += i.first;
  }
  cout << answer;
  return 0;
}
