#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbg(const char *xn, T x) {
  if (0) cout << xn << ": " << x << "\n";
}
template <class T, class... TA>
void dbg(const char *xn, T x, TA... t) {
  while (*xn != ',')
    if (0) cout << *xn++;
  if (0) cout << ": " << x << ",";
  dbg(xn + 1, t...);
}
template <class T>
inline bool upd_max(T &x, T y) {
  return y > x ? x = y, true : false;
}
template <class T>
inline bool upd_min(T &x, T y) {
  return y < x ? x = y, true : false;
}
const int N = 200007;
long long n, m, path[N];
bitset<N> vis;
vector<pair<long long, long long> > G[N];
vector<long long> basis;
class gauss {
 public:
  gauss(){};
  void insert(long long tmp) {
    for (auto it : basis)
      if ((1LL << ((63 - __builtin_clzll(it)))) & tmp) tmp ^= it;
    if (tmp == 0) return;
    for (auto &it : basis)
      if ((1LL << ((63 - __builtin_clzll(tmp)))) & it) it ^= tmp;
    basis.push_back(tmp);
  }
};
gauss B;
void DFS(long long v, long long from) {
  vis[v] = 1;
  for (auto e : G[v]) {
    long long u = e.first, c = e.second;
    if (!vis[u]) {
      path[u] = path[v] ^ c;
      DFS(u, v);
    } else if (u != from) {
      B.insert(c ^ path[v] ^ path[u]);
    }
  }
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= (m); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }
  DFS(1, 0);
  if (0)
    if (0) cout << '\n';
  sort((basis).begin(), (basis).end());
  long long rst = path[n];
  for (auto x : basis) upd_min(rst, rst ^ x);
  cout << rst;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
