#include <bits/stdc++.h>
using namespace std;
struct LiBase {
  int a[63];
  void init() { memset(a, 0, sizeof(a)); }
  bool insert_(int x) {
    for (int i = 62; i >= 0 && x; i--)
      if (x & (1LL << i)) {
        if (!a[i]) {
          a[i] = x;
          break;
        } else
          x ^= a[i];
      }
    return x > 0;
  }
  int query_min(int x) {
    int ans = x;
    for (int i = 62; i >= 0; i--) {
      if ((ans ^ a[i]) < ans) ans ^= a[i];
    }
    return ans;
  }
};
const int maxv = 100010;
const int maxe = 100010;
int head[maxv];
int cnt = 0;
struct Edge {
  int v, nex;
  int w;
  Edge(int v = 0, int w = 0, int nex = 0) : v(v), w(w), nex(nex) {}
} e[maxe << 1];
void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}
void add(int u, int v, int w) {
  e[cnt] = Edge(v, w, head[u]);
  head[u] = cnt++;
  e[cnt] = Edge(u, w, head[v]);
  head[v] = cnt++;
}
LiBase lb;
int n, m;
int dfsk;
int dis[maxv], pre[maxv];
void dfs(int u, int id) {
  pre[u] = ++dfsk;
  for (int i = head[u]; ~i; i = e[i].nex) {
    if (i == (id ^ 1)) continue;
    int v = e[i].v;
    if (!pre[v]) {
      dis[v] = e[i].w ^ dis[u];
      dfs(v, i);
    } else if (pre[v] < pre[u])
      lb.insert_(dis[u] ^ e[i].w ^ dis[v]);
  }
}
void get_cir() {
  memset(pre, 0, sizeof(pre));
  memset(dis, 0, sizeof(dis));
  dfsk = 0;
  dfs(1, -1);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    int u, v, w;
    init();
    lb.init();
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d", &u, &v, &w);
      if (u != v)
        add(u, v, w);
      else
        lb.insert_(w);
    }
    get_cir();
    int ans = lb.query_min(dis[n]);
    printf("%d\n", ans);
  }
  return 0;
}
