#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using LD = long double;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
template <typename T>
struct LnBase {
  int sz, szc;
  vector<T> x;
  vector<int> y;
  LnBase() {
    sz = sizeof(T) << 3;
    szc = -1;
    x.resize(sz);
    y.resize(sz);
  }
  T operator[](int h) { return x[h]; }
  int insert(T v) {
    for (int i = sz - 1; i >= 0; i--) {
      if (v >> i & 1) {
        if (!x[i]) {
          x[i] = v;
          szc = -1;
          return i;
        }
        v ^= x[i];
      }
    }
    return -1;
  }
  int find(T v) {
    for (int i = sz - 1; i >= 0; i--) {
      if (v >> i & 1 && x[i]) v ^= x[i];
      if (!v) return 1;
    }
    return 0;
  }
  T Max(T s = 0) {
    for (int i = sz - 1; i >= 0; i--) {
      s = max(s, s ^ x[i]);
    }
    return s;
  }
  T Min(T s) {
    for (int i = sz - 1; i >= 0; i--) {
      s = min(s, s ^ x[i]);
    }
    return s;
  }
  void Canonicity() {
    for (int i = sz - 1; i > 0; i--) {
      for (int j = i - 1; j >= 0; j--) {
        if (x[i] >> j & 1) x[i] ^= x[j];
      }
    }
    szc = 0;
    for (int i = 0; i < sz; i++)
      if (x[i]) y[szc++] = i;
  }
  T Kth(T K) {
    if (szc < 0) Canonicity();
    if (K >= (T)1 << szc) return -1;
    T s = 0;
    for (int i = szc - 1; i >= 0; i--)
      if (K >> i & 1) s ^= x[y[i]];
    return s;
  }
};
struct node {
  int v, w;
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<node>> lj(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    lj[u].push_back({v, w});
    lj[v].push_back({u, w});
  }
  vector<int> us(n, -1);
  LnBase<int> b;
  function<void(int)> dfs = [&](int k) {
    for (auto& i : lj[k]) {
      if (us[i.v] != -1) {
        b.insert(us[i.v] ^ us[k] ^ i.w);
      } else {
        us[i.v] = us[k] ^ i.w;
        dfs(i.v);
      }
    }
  };
  us[0] = 0;
  dfs(0);
  cout << b.Min(us[n - 1]) << '\n';
  return 0;
}
