#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
const int N = 1e5 + 5, mod = 1e9 + 7;
int base[35];
void insert(int x) {
  for (int i = 30; i >= 0; i--) {
    if (!(x >> i) & 1) continue;
    if (base[i]) {
      x ^= base[i];
    } else {
      for (int j = i - 1; j >= 0; j--) {
        if ((x >> j) & 1) x ^= base[j];
      }
      for (int j = i + 1; j <= 30; j++) {
        if ((base[j] >> i) & 1) base[j] ^= x;
      }
      base[i] = x;
      break;
    }
  }
}
V<pair<int, int>> G[N];
int val[N];
bool vis[N];
void dfs(int u, int cur) {
  val[u] = cur, vis[u] = 1;
  for (auto& v : G[u]) {
    if (vis[v.first]) {
      insert(val[u] ^ val[v.first] ^ v.second);
    } else {
      dfs(v.first, cur ^ v.second);
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w}), G[v].push_back({u, w});
  }
  dfs(1, 0);
  int ans = val[1] ^ val[n];
  for (int i = 30; i >= 0; i--) {
    ans = min(ans, ans ^ base[i]);
  }
  cout << ans << "\n";
}
