#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
void Swap(T &x, T &y) {
  T z = x;
  x = y;
  y = z;
}
const int MAXL = 62;
const int N = 1e6 + 5;
const int M = 1e6 + 5;
long long edge[M << 1];
int nxt[M << 1], ver[M << 1], head[N], tot;
void addEdge(int u, int v, long long w) {
  nxt[++tot] = head[u];
  edge[tot] = w;
  ver[tot] = v;
  head[u] = tot;
}
int n, m;
int vis[N];
long long ans;
long long dis[N];
struct LinearBasis {
  long long a[MAXL + 5], num[MAXL + 5];
  LinearBasis() { memset(a, 0, sizeof a); }
  long long operator[](int x) { return a[x]; }
  void insert(long long x) {
    for (int i = MAXL; i >= 0; --i) {
      if (!((x >> i) & 1)) continue;
      if (a[i])
        x ^= a[i];
      else {
        for (int j = 0; j < i; ++j)
          if ((x >> j) & 1) x ^= a[j];
        for (int j = i + 1; j <= MAXL; ++j)
          if ((a[j] >> i) & 1) a[j] ^= x;
        a[i] = x;
        return;
      }
    }
  }
} A;
void dfs(int u) {
  vis[u] = 1;
  for (int e = head[u]; e; e = nxt[e]) {
    int v = ver[e];
    if (vis[v])
      A.insert(dis[u] ^ dis[v] ^ edge[e]);
    else
      dis[v] = dis[u] ^ edge[e], dfs(v);
  }
}
int main() {
  read(n);
  read(m);
  int u, v;
  long long w;
  for (int i = 1; i <= m; ++i) {
    read(u);
    read(v);
    read(w);
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  dfs(1);
  ans = dis[n];
  for (int i = MAXL; i >= 0; --i) ans = Min(ans, ans ^ A.a[i]);
  print(ans);
  return 0;
}
