#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int T;
struct graph {
  int head[N], nxt[N << 1], to[N << 1], sz;
  long long w[N << 1];
  void init() { memset(head, 0, sizeof(head)), sz = 0; }
  graph() { init(); }
  void push(int a, int b, long long c) {
    nxt[++sz] = head[a], to[sz] = b, w[sz] = c, head[a] = sz;
  }
  int &operator[](const int a) { return to[a]; }
} g;
long long d[70];
void insert(long long x) {
  for (int j = 63; j >= 0; j--) {
    if ((x >> j) & 1) {
      if (d[j])
        x ^= d[j];
      else {
        d[j] = x;
        break;
      }
    }
  }
}
long long query(long long x) {
  long long res = x;
  for (int j = 63; j >= 0; j--)
    if ((res ^ d[j]) < res) res = res ^ d[j];
  return res;
}
int vis[N];
long long val[N];
void dfs(int u, long long preval) {
  val[u] = preval, vis[u] = 1;
  for (int i = g.head[u]; i; i = g.nxt[i]) {
    if (!vis[g[i]])
      dfs(g[i], preval ^ g.w[i]);
    else
      insert(preval ^ g.w[i] ^ val[g[i]]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    g.push(a, b, c);
    g.push(b, a, c);
  }
  dfs(1, 0);
  printf("%lld\n", query(val[n]));
  return 0;
}
