#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, m;
bool vis[MAXN];
int ans[MAXN];
vector<pair<int, int>> G[MAXN];
vector<int> base;
void add(int x) {
  for (auto elem : base) {
    x = min(x, x ^ elem);
  }
  if (x) base.push_back(x);
}
void dfs(int u, int cost) {
  vis[u] = 1, ans[u] = cost;
  for (auto elem : G[u]) {
    int v = elem.first, c = elem.second;
    if (vis[v]) {
      add(ans[v] ^ cost ^ c);
    } else
      dfs(v, cost ^ c);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    G[u].push_back({v, c});
    G[v].push_back({u, c});
  }
  dfs(1, 0);
  for (auto elem : base) ans[n] = min(ans[n], ans[n] ^ elem);
  cout << ans[n] << endl;
}
