#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, m;
int cost[MAXN];
int parent_cost[MAXN];
int visited[MAXN];
vector<pair<int, int>> adj[MAXN];
vector<int> cycle_basis;
void add_cycle(int x) {
  int s = (int)cycle_basis.size();
  if (s == 0) {
    cycle_basis.push_back(x);
    return;
  }
  for (int z : cycle_basis) {
    x = min(x, x ^ z);
  }
  if (x > 0) {
    cycle_basis.push_back(x);
    s = s + 1;
    for (int i = s - 2; i >= 0; i--) {
      if (cycle_basis[i] < cycle_basis[i + 1])
        swap(cycle_basis[i], cycle_basis[i + 1]);
    }
  }
}
void dfs(int u, int p) {
  visited[u] = true;
  for (auto e : adj[u]) {
    int v = e.first;
    int w = e.second;
    if (v != p || (v == p && parent_cost[v] != w)) {
      if (!visited[v]) {
        cost[v] = cost[u] ^ w;
        parent_cost[v] = w;
        dfs(v, u);
      } else {
        add_cycle(cost[u] ^ cost[v] ^ w);
      }
    }
  }
}
inline int solve(int p) {
  for (int x : cycle_basis) {
    p = min(p, p ^ x);
  }
  return p;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    adj[x].push_back(make_pair(y, w));
    adj[y].push_back(make_pair(x, w));
  }
  dfs(1, 0);
  int path = cost[1] ^ cost[n];
  cout << solve(path) << endl;
}
