#include <bits/stdc++.h>
using namespace std;
const int MN = 100005, LOG = 28;
int used[MN], val[MN], blocked[MN];
vector<pair<int, int> > G[MN];
vector<int> cykle;
int n, res;
void dfs(int x, int ksor, int p) {
  used[x] = 1;
  val[x] = ksor;
  if (x == n) res = ksor;
  int s = G[x].size();
  for (int i = 0; i < s; ++i) {
    if (!used[G[x][i].first])
      dfs(G[x][i].first, ksor ^ G[x][i].second, x);
    else if (G[x][i].first != p)
      cykle.push_back(val[x] ^ val[G[x][i].first] ^ G[x][i].second);
  }
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  dfs(1, 0, 0);
  int s = cykle.size();
  for (int i = LOG; i >= 0; --i) {
    int p2 = (1 << i), curr = -1;
    for (int i = 0; i < s; ++i) {
      if (!blocked[i] && (cykle[i] & p2)) {
        if (curr == -1) {
          curr = cykle[i];
          blocked[i] = 1;
          if (res & p2) res ^= curr;
        } else {
          cykle[i] ^= curr;
        }
      }
    }
  }
  printf("%d", res);
}
