#include <bits/stdc++.h>
using namespace std;
const int maxn = 101000;
struct edge {
  int to, nex, dis;
} e[maxn << 1];
vector<int> G;
int n, m, cnt;
int head[maxn], vis[maxn], val[maxn];
void add(int x, int y, int z) {
  e[++cnt].to = y;
  e[cnt].dis = z;
  e[cnt].nex = head[x];
  head[x] = cnt;
}
void add(int x) {
  for (int i = 0; i < G.size(); i++) x = min(x, x ^ G[i]);
  if (x) G.push_back(x);
}
void dfs(int u, int now) {
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].nex) {
    int v = e[i].to;
    if (vis[v])
      add(val[v] ^ now ^ e[i].dis);
    else {
      val[v] = now ^ e[i].dis;
      dfs(v, val[v]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1, 0);
  for (int i = 0; i < G.size(); i++) val[n] = min(val[n], val[n] ^ G[i]);
  printf("%d\n", val[n]);
  return 0;
}
