#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int DIM = 32;
vector<pair<int, int>> g[N];
int n, m, dist[N];
int d, basis[30];
void add(int w) {
  if (!d) return void(basis[d++] = w);
  for (int i = 0; i < d; i++) w = min(w, w ^ basis[i]);
  if (w) {
    basis[d++] = w;
    for (int i = d - 1; i > 0; i--)
      if (basis[i] > basis[i - 1]) swap(basis[i], basis[i - 1]);
  }
}
void dfs(int v, int XOR = 0) {
  dist[v] = XOR;
  for (auto pxt : g[v]) {
    int xt = pxt.first, w = pxt.second;
    if (dist[xt] != -1)
      add(dist[v] ^ dist[xt] ^ w);
    else
      dfs(xt, XOR ^ w);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  memset(dist, -1, sizeof(dist));
  dfs(1);
  int sol = dist[n];
  for (int i = 0; i < d; i++) sol = min(sol, sol ^ basis[i]);
  printf("%d\n", sol);
  return 0;
}
