#include <bits/stdc++.h>
using namespace std;
const int LG = 30;
struct Gauss {
  array<int, LG> vet;
  int size;
  Gauss() : size(0) { fill(vet.begin(), vet.end(), 0); }
  int add(int val) {
    for (int i = LG - 1; i >= 0; i--)
      if (val >> i & 1) {
        if (vet[i] == 0) {
          vet[i] = val;
          size++;
          return i;
        }
        val ^= vet[i];
      }
    return -1;
  }
};
const int N = 100005;
vector<pair<int, int>> g[N];
int val[N];
void dfs(int u, int p) {
  for (auto [v, w] : g[u])
    if (v != p) {
      val[v] = val[u] ^ w;
      dfs(v, u);
    }
}
int p[N];
int f(int u) { return u == p[u] ? u : p[u] = f(p[u]); }
int main() {
  iota(p, p + N, 0);
  int n, m;
  scanf("%d %d", &n, &m);
  vector<tuple<int, int, int>> edges;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (f(a) == f(b))
      edges.emplace_back(a, b, c);
    else {
      g[a].emplace_back(b, c);
      g[b].emplace_back(a, c);
      p[f(a)] = f(b);
    }
  }
  dfs(1, 1);
  Gauss x;
  for (auto [a, b, c] : edges) {
    x.add(val[a] ^ val[b] ^ c);
  }
  int ans = val[1] ^ val[n];
  for (int i = LG - 1; i >= 0; i--)
    if (ans >> i & 1) {
      ans ^= x.vet[i];
    }
  printf("%d\n", ans);
}
