#include <bits/stdc++.h>
using namespace std;
const int rlen = 1 << 18 | 1;
inline char gc() {
  static char buf[rlen], *ib, *ob;
  (ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin));
  return ib == ob ? -1 : *ib++;
}
inline int read() {
  int ans = 0;
  char ch = gc();
  while (!isdigit(ch)) ch = gc();
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
const int N = 1e5 + 5;
vector<pair<int, int> > e[N];
int n, m, dis[N];
bool vis[N];
namespace xxj {
int a[31];
inline void insert(int x) {
  if (!x) return;
  for (register int i = 30; ~i; --i)
    if ((x >> i) & 1)
      if (!a[i]) {
        a[i] = x;
        break;
      } else
        x ^= a[i];
}
inline int query(int x) {
  for (register int i = 30; ~i; --i) x = min(x, x ^ a[i]);
  return x;
}
}  // namespace xxj
void dfs(int p, int fa) {
  vis[p] = 1;
  for (register int i = 0, v; i < e[p].size(); ++i) {
    if ((v = e[p][i].first) == fa) continue;
    if (!vis[v])
      dis[v] = dis[p] ^ e[p][i].second, dfs(v, p);
    else
      xxj::insert(dis[v] ^ dis[p] ^ e[p][i].second);
  }
}
int main() {
  n = read(), m = read();
  for (register int i = 1, u, v, w; i <= m; ++i)
    u = read(), v = read(), w = read(), e[u].push_back(pair<int, int>(v, w)),
    e[v].push_back(pair<int, int>(u, w));
  dfs(1, 0), cout << xxj::query(dis[n]);
  return 0;
}
