#include <bits/stdc++.h>
const int K = 30, N = 200000, M = 400000;
int n, m, hd[N + 5], cnt = 0;
long long v[K + 5], w[N + 5];
bool inq[N + 5];
struct edge {
  int to, nxt;
  long long val;
  inline edge() {}
  inline edge(int _to, int _nxt, long long _val)
      : to(_to), nxt(_nxt), val(_val) {}
} e[M + 5];
inline void chkmin(long long& a, long long b) {
  if (b < a) a = b;
}
inline bool chkbit(long long x, int j) { return x & (1LL << j); }
inline void add(int f, int t, long long w) {
  e[++cnt] = edge(t, hd[f], w);
  hd[f] = cnt;
}
inline void chk(long long x) {
  for (int j = K; j >= 0; --j)
    if (chkbit(x, j)) {
      if (!v[j]) {
        v[j] = x;
        return;
      } else
        x ^= v[j];
    }
}
void dfs(int x) {
  inq[x] = true;
  for (int i = hd[x]; i; i = e[i].nxt) {
    if (inq[e[i].to])
      chk(w[x] ^ w[e[i].to] ^ e[i].val);
    else {
      w[e[i].to] = w[x] ^ e[i].val;
      dfs(e[i].to);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int s, t;
    long long d;
    scanf("%d %d %lld", &s, &t, &d);
    add(s, t, d);
    add(t, s, d);
  }
  dfs(1);
  long long ans = w[n];
  for (int j = K; j >= 0; --j) chkmin(ans, ans ^ v[j]);
  printf("%lld\n", ans);
}
