#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, x, y, z, d[N], q[40];
vector<pair<int, int> > g[N];
bool used[N];
inline void add(int x) {
  for (int i = 29; i >= 0; i--) {
    if ((x >> i) & 1) {
      if (q[i] == -1) {
        q[i] = x;
        break;
      } else {
        x ^= q[i];
      }
    }
  }
}
void dfs(int v = 1) {
  used[v] = true;
  for (auto it : g[v]) {
    int to = it.first, len = it.second;
    if (used[to]) {
      add(d[v] ^ len ^ d[to]);
    } else {
      d[to] = d[v] ^ len;
      dfs(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  memset(q, -1, sizeof(q));
  dfs();
  int ans = d[n];
  for (int i = 29; i >= 0; i--) {
    if (q[i] != -1) {
      ans = min(ans, ans ^ q[i]);
    }
  }
  cout << ans;
}
