#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int n, m, d[MAX];
vector<pair<int, int> > g[MAX];
struct edge {
  int a, b, c;
  edge(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
} e[MAX];
struct basis {
  int t;
  vector<int> v;
  basis(int t_) {
    t = t_;
    v.assign(t, 0);
  }
  bool add_vector(int k) {
    for (int i = t - 1; i >= 0; i--) {
      if (k >> i & 1) {
        if (v[i] == 0) {
          v[i] = k;
          break;
        } else
          k ^= v[i];
      }
    }
    return !k ? true : false;
  }
};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    e[i] = edge(x, y, w);
    g[x].push_back({y, w});
    g[y].push_back({x, w});
  }
  queue<int> q;
  q.push(1);
  for (int i = 2; i <= n; i++) d[i] = -1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto o : g[u]) {
      int v = o.first;
      int c = o.second;
      if (d[v] == -1) {
        d[v] = d[u] ^ c;
        q.push(v);
      }
    }
  }
  basis B(30);
  for (int i = 1; i <= m; i++) {
    int v = d[e[i].a] ^ d[e[i].b] ^ e[i].c;
    B.add_vector(v);
  }
  int ans = 0;
  for (int i = 29; i >= 0; i--) {
    if (d[n] >> i & 1) {
      if (B.v[i] > 0)
        d[n] ^= B.v[i];
      else
        ans |= 1 << i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
