#include <bits/stdc++.h>
using namespace std;
struct linear_basis {
  long long p[63 + 5];
  void insert(long long v) {
    for (long long i = 63; i >= 0; i--) {
      if ((v >> i) & 1) {
        if (p[i])
          v ^= p[i];
        else {
          p[i] = v;
          break;
        }
      }
    }
  }
  long long query(long long v) {
    long long ans = v;
    for (int i = 63; i >= 0; i--) ans = min(ans, ans ^ p[i]);
    return ans;
  }
} T;
int n, m;
struct edge {
  int from;
  int to;
  int next;
  long long len;
} E[100000 * 2 + 5];
int head[100000 + 5];
int esz = 1;
void add_edge(int u, int v, long long w) {
  esz++;
  E[esz].from = u;
  E[esz].to = v;
  E[esz].len = w;
  E[esz].next = head[u];
  head[u] = esz;
}
long long dist[100000 + 5];
bool vis[100000 + 5];
void dfs(int x, long long d) {
  dist[x] = d;
  vis[x] = 1;
  for (int i = head[x]; i; i = E[i].next) {
    int y = E[i].to;
    if (!vis[y])
      dfs(y, d ^ E[i].len);
    else
      T.insert(d ^ E[i].len ^ dist[y]);
  }
}
int main() {
  int u, v;
  long long w;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %lld", &u, &v, &w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  dfs(1, 0);
  printf("%lld\n", T.query(dist[n]));
}
