#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, nxt, val;
} e[100005 * 2];
int n, m, tot, head[100005], zz, p[35], val[100005], x[100005 * 2];
bool vis[100005];
void build(int a, int b, int c) {
  e[++tot].to = b;
  e[tot].nxt = head[a];
  head[a] = tot;
  e[tot].val = c;
}
void dfs(int p, int fa, int Xor) {
  val[p] = Xor;
  vis[p] = true;
  for (int i = head[p]; i; i = e[i].nxt) {
    if (e[i].to == fa) continue;
    if (!vis[e[i].to]) {
      dfs(e[i].to, p, Xor ^ e[i].val);
    } else if (e[i].to >= p) {
      x[++zz] = Xor ^ val[e[i].to] ^ e[i].val;
    }
  }
}
void ins(int a) {
  int j = 1 << 30;
  for (int i = 30; i >= 0; --i, j >>= 1) {
    if (a & j) {
      if (!p[i]) {
        p[i] = a;
        return;
      }
      a ^= p[i];
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int a, b, c, i = 1; i <= m; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    build(a, b, c);
    if (a != b) build(b, a, c);
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= zz; ++i) ins(x[i]);
  int j = 1 << 30, ans = val[n];
  for (int i = 30; i >= 0; --i, j >>= 1) {
    if (ans & j) ans ^= p[i];
  }
  printf("%d", ans);
  return 0;
}
