#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  int ch = getchar(), f = 0;
  long long x = 0;
  while (ch < '0' || ch > '9') {
    f |= ch == '-';
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
struct eric {
  int to, next;
  long long v;
} edge[1000005 << 1];
int head[1000005], size;
int n, m;
long long f[1000005];
int vis[1000005];
inline void add(int x, int y, long long z) {
  edge[++size].to = y;
  edge[size].v = z;
  edge[size].next = head[x];
  head[x] = size;
}
struct Liner_base {
  long long a[64];
  inline void add(long long x) {
    for (int i = 62; ~i; i--)
      if ((x >> i) & 1) {
        if (a[i])
          x ^= a[i];
        else {
          a[i] = x;
          break;
        }
      }
  }
  inline long long get_max(long long ini) {
    long long ret = ini;
    for (int i = 62; ~i; i--) {
      if ((ret ^ a[i]) < ret) ret ^= a[i];
    }
    return ret;
  }
} lb;
void dfs(int pos) {
  vis[pos] = 1;
  for (int i = head[pos]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (vis[v])
      lb.add(f[pos] ^ edge[i].v ^ f[v]);
    else
      f[v] = f[pos] ^ edge[i].v, dfs(v);
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1, x, y; i <= m; i++) {
    x = read(), y = read();
    long long z = read();
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1);
  printf("%lld\n", lb.get_max(f[n]));
  return 0;
}
