#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
const int MAXN = 111111;
vector<int> V;
vector<int> adj[MAXN];
vector<int> b[MAXN];
int n, m, Q;
int dis[MAXN], e[MAXN], c[MAXN], chk[MAXN], vis[MAXN];
int f[MAXN];
inline int get(int u) { return f[u] == 0 ? u : f[u] = get(f[u]); }
void dfs(int u, int d) {
  chk[u] = 1, dis[u] = d;
  for (int i = 0; i < ((int)(adj[u].size())); i++) {
    int j = adj[u][i], v = e[j] ^ u, w = c[j];
    if (!chk[v]) {
      vis[j] = 1, dfs(v, d ^ w);
    } else if (!vis[j]) {
      V.push_back(dis[u] ^ dis[v] ^ w);
    }
  }
}
void solve(int u) {
  int j = 0;
  for (int i = 0; j < ((int)(V.size())) && i < 30; i++) {
    for (int k = j; k < ((int)(V.size())); k++) {
      if (V[k] >> (29 - i) & 1) {
        if (k > j) {
          swap(V[j], V[k]);
          break;
        }
      }
    }
    if (V[j] >> (29 - i) & 1) {
      for (int k = 0; k < ((int)(V.size())); k++) {
        if (k != j) {
          if (V[k] >> (29 - i) & 1) {
            V[k] ^= V[j];
          }
        }
      }
      j++;
    }
  }
  if (j < ((int)(V.size()))) {
    V.resize(j);
  }
  b[u] = V;
}
int main() {
  cin >> n >> m;
  Q = 1;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    int x = get(u), y = get(v);
    if (x != y) {
      f[x] = y;
    }
    adj[u].push_back(i);
    adj[v].push_back(i);
    c[i] = w, e[i] = u ^ v;
  }
  for (int i = 1; i <= n; i++) {
    if (get(i) == i) {
      V.clear();
      dfs(i, 0);
      solve(i);
    }
  }
  for (int i = 0; i < Q; i++) {
    int u = 1, v = n;
    int x = get(u), y = get(v);
    if (x != y) {
      puts("XIT");
      continue;
    }
    int ans = dis[u] ^ dis[v];
    for (int l = 29; l >= 0; l--) {
      for (int k = 0; k < ((int)(b[x].size())); k++) {
        if ((ans ^ b[x][k]) < ans) {
          ans ^= b[x][k];
          break;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
