#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
const int maxm = 1e5 + 1;
const int maxlg = 63;
struct Node {
  int to, next;
  long long val;
} e[maxm << 1];
int head[maxn];
long long xr[maxn];
long long b[maxn];
bool vis[maxn];
int cnt, n;
void add(int x, int y, long long z) {
  e[cnt].to = y;
  e[cnt].val = z;
  e[cnt].next = head[x];
  head[x] = cnt++;
}
void insert(long long x) {
  for (int i = maxlg - 1; i >= 0; i--)
    if (x & 1ll << i)
      if (!b[i]) {
        b[i] = x;
        break;
      } else
        x ^= b[i];
}
void dfs(int x, int fedge) {
  vis[x] = 1;
  for (int i = head[x]; i != -1; i = e[i].next) {
    if (i == (fedge ^ 1)) continue;
    int v = e[i].to;
    if (vis[v])
      insert(xr[x] ^ xr[v] ^ e[i].val);
    else
      xr[v] = xr[x] ^ e[i].val, dfs(v, i);
  }
}
int main() {
  int m, x, y;
  long long z;
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d%lld", &x, &y, &z);
    add(x, y, z), add(y, x, z);
  }
  dfs(1, -1);
  long long ans = xr[n];
  for (int i = maxlg - 1; i >= 0; i--)
    if (b[i] && ans & 1ll << i) ans ^= b[i];
  printf("%lld", ans);
  return 0;
}
