#include <bits/stdc++.h>
using namespace std;
struct LinearBase {
  const int n = 30;
  vector<int> pivot = vector<int>(n);
  void Insert(int curr) {
    for (int bit = n - 1; bit >= 0 && curr != 0; --bit) {
      if ((curr & (1 << bit)) != 0) {
        curr ^= pivot[bit];
      }
    }
    if (curr == 0) return;
    int msb = 31 - __builtin_clz(curr);
    assert(pivot[msb] == 0);
    pivot[msb] = curr;
    for (int bit = n - 1; bit > msb; --bit) {
      if ((pivot[bit] & (1 << bit)) != 0) {
        pivot[bit] ^= curr;
      }
    }
  }
  int Query(int ans) {
    for (int bit = n - 1; bit >= 0; --bit) {
      if ((ans & (1 << bit)) != 0) {
        ans ^= pivot[bit];
      }
    }
    return ans;
  }
};
struct Graph {
  int n;
  LinearBase base;
  vector<int> dist;
  vector<vector<pair<int, int>>> adj;
  Graph(int n_) : n(n_), dist(n, -1), adj(n) {}
  void AddEdge(int a, int b, int w) {
    adj[a].emplace_back(b, w);
    adj[b].emplace_back(a, w);
  }
  void DFS(int node) {
    for (auto &e : adj[node]) {
      int x, w;
      tie(x, w) = e;
      if (dist[x] == -1) {
        dist[x] = dist[node] ^ w;
        DFS(x);
      } else {
        base.Insert(dist[node] ^ dist[x] ^ w);
      }
    }
  }
  int Solve() {
    dist[0] = 0;
    DFS(0);
    return base.Query(dist[n - 1]);
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    cin >> a >> b >> w;
    g.AddEdge(a - 1, b - 1, w);
  }
  cout << g.Solve() << endl;
}
