#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> adj[100010];
set<long long> weights[100010];
set<long long> res;
long long n, m, u, v, w;
void bfs() {
  priority_queue<pair<long long, long long>> q;
  q.push({1, 0});
  long long sz = 1;
  weights[1].insert(0);
  for (; q.size(); sz = q.size()) {
    while (sz--) {
      auto U = q.top().first, W = q.top().second;
      q.pop();
      if (U == n) res.insert(W);
      for (auto V : adj[U]) {
        if (weights[V.first].find(W ^ V.second) == weights[V.first].end()) {
          weights[V.first].insert(W ^ V.second);
          q.push({V.first, (W ^ V.second)});
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  if (m > n * 2) return cout << 0, 0;
  bfs();
  cout << *res.begin();
  return 0;
}
