#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N * 2], tot, n, m, x, y, c, vis[N], to[N];
vector<pair<int, int> > e[N];
void Gauss_xor(int *a, int n) {
  for (int u = 1 << 30, p = 0, x; u; u >>= 1) {
    for (x = ++p; x <= n; ++x)
      if (a[x] & u) break;
    if (x > n) {
      p--;
      continue;
    }
    swap(a[p], a[x]);
    for (int i = (1); i <= (n); ++i)
      if (i != p && (a[i] & u)) a[i] ^= a[p];
  }
}
void dfs(int x, int val) {
  vis[x] = 1, to[x] = val;
  for (auto it : e[x])
    if (vis[it.first])
      a[++tot] = to[x] ^ it.second ^ to[it.first];
    else
      dfs(it.first, val ^ it.second);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d%d", &x, &y, &c);
    e[x].push_back(pair<int, int>(y, c));
    e[y].push_back(pair<int, int>(x, c));
  }
  dfs(1, 0), Gauss_xor(a, tot);
  int ans = to[n];
  for (int i = 1; a[i]; i++) ans = min(ans, ans ^ a[i]);
  printf("%d\n", ans);
  return 0;
}
