#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Edge {
  int to, dis, nxt;
} E[N << 1];
int n, m, cnt, head[N], d[N], dis[N];
bool vis[N];
void addedg(int u, int v, int w) {
  E[++cnt] = (Edge){v, w, head[u]};
  head[u] = cnt;
}
void insert(int x) {
  for (int i = 30; i >= 0; i--)
    if (x & (1 << i)) {
      if (d[i])
        x ^= d[i];
      else {
        d[i] = x;
        break;
      }
    }
}
void dfs(int u) {
  vis[u] = true;
  for (int i = head[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if (!vis[v]) {
      dis[v] = dis[u] ^ E[i].dis;
      dfs(v);
    } else
      insert(dis[u] ^ E[i].dis ^ dis[v]);
  }
}
int ask(int res) {
  for (int i = 30; i >= 0; i--) res = min(res, res ^ d[i]);
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedg(u, v, w);
    addedg(v, u, w);
  }
  dfs(1);
  printf("%d", ask(dis[n]));
  return 0;
}
