#include <bits/stdc++.h>
using namespace std;
vector<array<long long int, 2>> g[100005];
bool vis[100005];
long long int Xor[100005];
vector<long long int> cycle;
void dfs(long long int node, long long int par, long long int cur_xor) {
  vis[node] = 1;
  Xor[node] = cur_xor;
  for (auto it : g[node]) {
    if (it[0] == par) {
      continue;
    }
    if (vis[it[0]]) {
      cycle.push_back(cur_xor ^ it[1] ^ Xor[it[0]]);
      continue;
    }
    dfs(it[0], node, cur_xor ^ it[1]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  dfs(1, 0, 0);
  vector<long long int> unq_xor;
  for (long long int i = 30; i >= 0; i--) {
    bool found_flg = 0;
    for (auto& it : cycle) {
      if (it & (1ll << i)) {
        swap(it, cycle.back());
        found_flg = 1;
        break;
      }
    }
    if (!found_flg) {
      continue;
    }
    long long int z = cycle.back();
    unq_xor.push_back(z);
    cycle.pop_back();
    for (auto& it : cycle) {
      if (it & (1ll << i)) {
        it ^= z;
      }
    }
  }
  long long int ans = Xor[n];
  for (auto it : unq_xor) {
    ans = min(ans, ans ^ it);
  }
  cout << ans << "\n";
}
