#include <bits/stdc++.h>
using namespace std;
void file(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
  long long fh = 1;
  char c = getchar();
  x = 0;
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c & 15);
    c = getchar();
  }
  x *= fh;
}
long long d[70];
void ins(long long x) {
  for (long long i = 62; ~i; --i) {
    if ((x >> i) & 1) {
      if (!d[i]) {
        d[i] = x;
        return;
      }
      x ^= d[i];
    }
  }
}
long long gm(long long ret = 0) {
  for (long long i = 62; ~i; --i) {
    if (!d[i]) continue;
    if ((ret ^ d[i]) < ret) ret ^= d[i];
  }
  return ret;
}
struct Edge {
  long long f, t, w, nxt;
} edge[2000005];
long long head[1000005], etot = 1;
void add_edge(long long f, long long t, long long w = 0) {
  edge[++etot] = (Edge){f, t, w, head[f]};
  head[f] = etot;
}
long long n, m;
long long dfn[1000005], dis[1000005], tot;
void dfs(long long x, long long pa) {
  dfn[x] = ++tot;
  for (long long i = head[x]; i; i = edge[i].nxt) {
    long long y = edge[i].t, w = edge[i].w;
    if (y == pa) continue;
    if (dfn[y]) {
      ins(dis[x] ^ w ^ dis[y]);
    } else {
      dis[y] = (dis[x] ^ w);
      dfs(y, x);
    }
  }
}
signed main() {
  read(n);
  read(m);
  for (long long i = 1, u, v, w; i <= m; ++i) {
    read(u);
    read(v);
    read(w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  dfs(1, 0);
  printf("%lld\n", gm(dis[n]));
  return 0;
}
