#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 101000;
int base[N][33];
int n, m, q, u, v, w, vis[N], lab[N], tot;
vector<pair<int, int> > e[N];
void add(int x) {
  for (int i = 31 - 1; i >= 0; i--) {
    if (!base[tot][i] && ((x >> i) & 1)) {
      base[tot][i] = x;
      break;
    } else
      x = min(x, x ^ base[tot][i]);
  }
}
int query(int x, int tot) {
  for (int i = 31 - 1; i >= 0; i--) x = min(x, x ^ base[tot][i]);
  return x;
}
void dfs(int u) {
  vis[u] = tot;
  for (auto p : e[u]) {
    int v = p.first;
    if (vis[v]) {
      add(p.second ^ lab[u] ^ lab[v]);
      continue;
    }
    lab[v] = lab[u] ^ p.second;
    dfs(v);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    e[u].push_back({v, w});
    e[v].push_back({u, w});
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      tot++;
      dfs(i);
    }
  }
  cout << query(lab[1] ^ lab[n], vis[1]) << '\n';
}
