#include <bits/stdc++.h>
using namespace std;
char *fs, *ft, buf[1 << 15];
inline char getc() {
  return (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
             ? 0
             : *fs++;
}
inline long long read() {
  long long x = 0, f = 1;
  char ch = getc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getc();
  }
  return x * f;
}
const int MAXN = 100010;
int n, m, len;
long long f[62], e[MAXN << 1], d[MAXN];
int vis[MAXN];
int lin[MAXN], ver[MAXN << 1], nex[MAXN << 1];
inline void add(int x, int y, long long z) {
  ver[++len] = y;
  nex[len] = lin[x];
  lin[x] = len;
  e[len] = z;
}
inline void insert(long long x) {
  for (int i = 60; i >= 0; --i) {
    if (x & (1ll << i)) {
      if (!f[i]) {
        f[i] = x;
        return;
      } else
        x = x ^ f[i];
    }
    if (!x) return;
  }
}
inline void dfs(int x) {
  vis[x] = 1;
  for (int i = lin[x]; i; i = nex[i]) {
    int tn = ver[i];
    if (!vis[tn]) {
      d[tn] = d[x] ^ e[i];
      dfs(tn);
    } else
      insert(d[x] ^ d[tn] ^ e[i]);
  }
}
inline long long ask(long long x) {
  for (int i = 60; i >= 0; --i)
    if ((x ^ f[i]) < x) x = x ^ f[i];
  return x;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int x, y;
    long long z;
    x = read();
    y = read();
    z = read();
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1);
  printf("%lld\n", ask(d[n]));
  return 0;
}
