#include <bits/stdc++.h>
using namespace std;
long long head[100005], tot, vis[100005], val[100005], d[70], n, m, ans;
struct edge {
  long long to, nex, w;
} e[100005 << 2];
void add(long long x, long long y, long long w) {
  e[++tot].to = y;
  e[tot].nex = head[x];
  e[tot].w = w;
  head[x] = tot;
}
void insert(long long x) {
  for (long long i = 62; i >= 0; i--) {
    if (x & (1ll << i)) {
      if (!d[i]) {
        d[i] = x;
        return;
      } else
        x ^= d[i];
    }
  }
}
void dfs(long long x, long long res) {
  vis[x] = 1;
  val[x] = res;
  for (long long i = head[x]; i; i = e[i].nex) {
    if (vis[e[i].to])
      insert(res ^ e[i].w ^ val[e[i].to]);
    else
      dfs(e[i].to, res ^ e[i].w);
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, y, w;
  while (cin >> n >> m) {
    memset(head, 0, sizeof(head));
    tot = 0;
    for (long long i = 1; i <= m; i++) {
      cin >> x >> y >> w;
      add(x, y, w);
      add(y, x, w);
    }
    memset(d, 0, sizeof(d));
    memset(vis, 0, sizeof(vis));
    dfs(1, 0);
    ans = val[n];
    for (long long i = 62; i >= 0; i--)
      ans = (ans ^ d[i]) < ans ? ans ^ d[i] : ans;
    cout << ans << endl;
  }
  return 0;
}
