#include <bits/stdc++.h>
using namespace std;
int n, m, dis[100005], crc[100005], cnt = 0;
bool vis[100005];
int head[100005], nxt[200005], v[200005], w[200005], tot = 0;
int bas[27];
inline void add(int a, int b, int c) {
  tot++;
  nxt[tot] = head[a];
  head[a] = tot;
  v[tot] = b;
  w[tot] = c;
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
void dfs(int pos) {
  vis[pos] = 1;
  for (int i = head[pos]; i; i = nxt[i]) {
    if (!vis[v[i]]) {
      dis[v[i]] = dis[pos] ^ w[i];
      dfs(v[i]);
    } else {
      crc[++cnt] = dis[v[i]] ^ dis[pos] ^ w[i];
      if (!crc[cnt]) cnt--;
    }
  }
}
int main() {
  int i, j, a, b, c;
  n = read();
  m = read();
  for (i = 1; i <= m; i++) {
    a = read();
    b = read();
    c = read();
    add(a, b, c);
    add(b, a, c);
  }
  dis[1] = 0;
  dfs(1);
  for (i = 1; i <= cnt; i++) {
    for (j = 26; j >= 0; j--) {
      if (crc[i] & (1 << j)) {
        if (!bas[j]) {
          bas[j] = crc[i];
          break;
        } else {
          crc[i] ^= bas[j];
        }
      }
    }
  }
  int ans = dis[n];
  for (j = 26; j >= 0; j--) {
    if ((ans ^ bas[j]) < ans) {
      ans ^= bas[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}
