#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, val[maxn], mark[maxn], base[maxn];
vector<pair<int, int> > grafo[maxn], g[maxn];
vector<int> cycle;
void dfs(int u, int v) {
  mark[u] = 1;
  val[u] = v;
  for (auto x : grafo[u]) {
    if (mark[x.first]) {
      cycle.push_back(val[u] ^ x.second ^ val[x.first]);
    } else {
      dfs(x.first, v ^ x.second);
    }
  }
}
void gauss() {
  for (auto x : cycle) {
    for (int i = 30; i >= 0; i--) {
      if ((x >> i) & 1) {
        if (!base[i]) base[i] = x;
        x ^= base[i];
      }
    }
  }
}
int solve(int v) {
  for (int i = 30; i >= 0; i--) {
    if ((v >> i) & 1) v = min(v, v ^ base[i]);
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    grafo[u].push_back({v, w});
    grafo[v].push_back({u, w});
  }
  dfs(1, 0);
  gauss();
  cout << solve(val[n]) << endl;
}
