#include <bits/stdc++.h>
using namespace std;
struct EDGE {
  int next, to;
  long long val;
} edge[200050];
int n, m;
int head[100050] = {0}, tot = 0;
long long dis[100050] = {0};
long long p[100] = {0};
int vis[100050] = {0};
long long ans;
inline long long read() {
  long long x = 0;
  char ch = 0;
  bool w = true;
  while (!isdigit(ch)) {
    if (ch == '-') w = false;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? x : -x;
}
inline void add_edge(int u, int v, long long k) {
  edge[++tot].next = head[u];
  edge[tot].to = v;
  edge[tot].val = k;
  head[u] = tot;
}
inline void insert(long long x) {
  for (register int i = 61; i >= 0; --i) {
    if (!(x >> i)) continue;
    if (!p[i]) {
      p[i] = x;
      return;
    }
    x ^= p[i];
  }
}
inline long long query(long long x) {
  for (register int i = 61; i >= 0; --i)
    if ((x ^ p[i]) < x) x ^= p[i];
  return x;
}
inline void dfs(int u) {
  vis[u] = 1;
  for (register int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis[v]) {
      dis[v] = dis[u] ^ edge[i].val;
      dfs(v);
    } else
      insert(dis[u] ^ dis[v] ^ edge[i].val);
  }
}
inline int MAIN() {
  n = read(), m = read();
  long long c;
  for (register int i = 1, a, b; i <= m; ++i) {
    a = read(), b = read(), c = read();
    add_edge(a, b, c);
    add_edge(b, a, c);
  }
  dfs(1);
  ans = dis[n];
  cout << query(ans) << endl;
  return 0;
}
int lglj = MAIN();
int main() { ; }
