#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long p[30 + 5], w[200000 + 5];
bool inq[200000 + 5];
int n, m, head[200000 + 5], cnt = 0;
struct edge {
  int to, next;
  long long w;
} e[400000 + 5];
void ins(int f, int t, long long w) {
  e[++cnt] = (edge){t, head[f], w};
  head[f] = cnt;
}
void ins(long long x) {
  for (int j = 30; j >= 0; j--)
    if ((x & (1LL << j))) {
      if (!p[j]) {
        p[j] = x;
        return;
      } else
        x ^= p[j];
    }
}
void dfs(int x) {
  inq[x] = 1;
  for (int i = head[x]; i; i = e[i].next)
    if (inq[e[i].to])
      ins(w[x] ^ w[e[i].to] ^ e[i].w);
    else
      w[e[i].to] = w[x] ^ e[i].w, dfs(e[i].to);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    long long w = read();
    ins(u, v, w);
    ins(v, u, w);
  }
  dfs(1);
  long long ans = w[n];
  for (int j = 30; j >= 0; j--) ans = min(ans, ans ^ p[j]);
  cout << ans;
  return 0;
}
