#include <bits/stdc++.h>
const int N = 1e5 + 10, M = 1e5 + 10;
template <class type>
inline void read(type &in) {
  in = 0;
  char ch = getchar();
  short fh = 1;
  while (ch < 48 || ch > 57) fh = ch == '-' ? -1 : fh, ch = getchar();
  while (ch > 47 && ch < 58)
    in = (in << 3) + (in << 1) + ch - 48, ch = getchar();
  in *= fh;
}
int cnt, head[N];
struct edge {
  int to, next;
  long long w;
} e[M * 2];
inline void add(int a, int b, long long c) {
  e[++cnt].next = head[a];
  head[a] = cnt;
  e[cnt].to = b;
  e[cnt].w = c;
}
namespace Linear_Basic {
const int L = 63;
long long base[L + 10];
inline void insert(long long x) {
  for (int i = L; i + 1; i--)
    if ((x >> i) & 1)
      if (!base[i]) {
        base[i] = x;
        break;
      } else
        x ^= base[i];
}
inline long long query(long long x) {
  for (int i = L; i + 1; i--)
    if (x > (x ^ base[i])) x ^= base[i];
  return x;
}
}  // namespace Linear_Basic
using namespace Linear_Basic;
long long dis[N];
bool vis[N];
void dfs(int x, long long w) {
  vis[x] = 1;
  dis[x] = w;
  for (int i = head[x], y; i; i = e[i].next)
    if (vis[y = e[i].to])
      insert(w ^ e[i].w ^ dis[y]);
    else
      dfs(y, w ^ e[i].w);
}
int n, m;
int main() {
  read(n);
  read(m);
  int a, b;
  long long c;
  while (m--) read(a), read(b), read(c), add(a, b, c), add(b, a, c);
  dfs(1, 0);
  printf("%lld\n", query(dis[n]));
  return 0;
}
