#include <bits/stdc++.h>
using namespace std;
int ecnt, tot, dis[100010], vis[100010];
int c[100010], head[100010];
struct edge {
  int u, v, w, next;
} E[100010 << 1];
void addedge(int u, int v, int w) {
  E[++ecnt].v = v;
  E[ecnt].w = w;
  E[ecnt].next = head[u];
  head[u] = ecnt;
}
void add(int w) {
  for (int i = 1; i <= tot; i++)
    if ((w ^ c[i]) < w) w ^= c[i];
  if (!w) return;
  c[++tot] = w;
}
void dfs(int x) {
  vis[x] = 1;
  for (int i = head[x]; i; i = E[i].next) {
    int v = E[i].v;
    if (!vis[v]) {
      dis[v] = dis[x] ^ E[i].w;
      dfs(v);
    } else
      add((dis[x] ^ dis[v] ^ E[i].w));
  }
}
int main() {
  int n, m, u, v, w;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  dfs(1);
  for (int i = 1; i <= tot; i++)
    if ((dis[n] ^ c[i]) < dis[n]) dis[n] ^= c[i];
  printf("%d", dis[n]);
}
