#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<pair<int, int> > G[maxn];
int dis[maxn];
bool vis[maxn];
int loops[maxn];
int a[70];
int ls;
int n, m;
int u, v, w;
void dfs(int now, int s) {
  vis[now] = 1, dis[now] = s;
  int len = G[now].size();
  for (int i = 0; i < len; i++) {
    int v = G[now][i].first;
    int w = G[now][i].second;
    if (!vis[v])
      dfs(v, s ^ w);
    else
      loops[++ls] = s ^ dis[v] ^ w;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  dfs(1, 0);
  int answer = dis[n];
  for (int i = 1; i <= ls; i++) {
    for (int j = 31; j >= 0; j--) {
      if ((loops[i] >> j) & 1) {
        if (!a[j]) {
          a[j] = loops[i];
          break;
        } else
          loops[i] ^= a[j];
      }
    }
  }
  for (int i = 31; i >= 0; i--) {
    answer = min(answer, answer ^ a[i]);
  }
  printf("%d\n", answer);
  return 0;
}
