#include <bits/stdc++.h>
using namespace std;
const int MaxBasis = 63;
struct LB {
  long long base[MaxBasis + 10];
  void init() { memset(base, 0, sizeof(base)); }
  bool add(long long x) {
    for (int i = MaxBasis; i >= 0; i--) {
      if (x >> i & 1) {
        if (!base[i]) {
          base[i] = x;
          break;
        } else
          x ^= base[i];
      }
    }
  }
  long long Max(long long ans = 0) {
    for (int i = MaxBasis; i >= 0; --i) {
      ans = max(ans, ans ^ base[i]);
    }
    return ans;
  }
  long long Min(long long ans = 0) {
    for (int i = MaxBasis; i >= 0; --i) {
      ans = min(ans, ans ^ base[i]);
    }
    return ans;
  }
} lb;
const int maxn = 1e6 + 10;
const int maxm = 1e6 + 10;
typedef struct node {
  int to, next;
  long long val;
} Edge;
Edge edge[maxn];
int head[maxn], tot;
bool vis[maxn];
long long circle[maxn], dist[maxn], cnt;
int n, m;
void addedge(int u, int v, long long val) {
  edge[tot].to = v;
  edge[tot].val = val;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis[v]) {
      dist[v] = dist[u] ^ edge[i].val;
      dfs(v);
    } else
      circle[++cnt] = dist[u] ^ dist[v] ^ edge[i].val;
  }
}
void init() {
  memset(head, -1, sizeof(head));
  memset(vis, 0, sizeof(vis));
  memset(dist, 0, sizeof(dist));
  tot = cnt = 0;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    init();
    int u, v;
    long long val;
    for (int i = 0; i < m; i++) {
      scanf("%d%d%I64d", &u, &v, &val);
      addedge(u, v, val);
      addedge(v, u, val);
    }
    lb.init();
    dfs(1);
    long long ans = dist[n];
    for (int i = 1; i <= cnt; i++) lb.add(circle[i]);
    printf("%I64d\n", lb.Min(ans));
  }
  return 0;
}
