#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int K = 32;
const int INF = 2e9 + 5;
int vis[MAX];
int val[MAX];
int basis[K];
int ans[MAX];
vector<pair<int, int> > adj[MAX];
vector<pair<int, int> > qu[MAX];
vector<int> ver;
int cur;
void add_cycle(int x) {
  for (int i = K - 1; i >= 0; i--) {
    if ((x >> i) & 1) {
      if (basis[i]) {
        x ^= basis[i];
      } else {
        basis[i] = x;
        break;
      }
    }
  }
}
void dfs(int s, int p) {
  vis[s] = cur;
  ver.push_back(s);
  for (auto pa : adj[s]) {
    int u = pa.first;
    int v = pa.second;
    if (u != p) {
      if (!vis[u]) {
        val[u] = val[s] ^ v;
        dfs(u, s);
      } else {
        add_cycle(val[u] ^ val[s] ^ v);
      }
    }
  }
}
int main() {
  int n, e;
  scanf("%d %d", &n, &e);
  for (int i = 1; i <= e; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  qu[1].push_back(make_pair(n, 1));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ver.clear();
      memset(basis, 0, sizeof(basis));
      cur++;
      dfs(i, 0);
      for (int j = 0; j < ver.size(); j++) {
        int x = ver[j];
        for (int k = 0; k < qu[x].size(); k++) {
          int a = qu[x][k].first;
          int b = qu[x][k].second;
          if (vis[a] != cur) {
            continue;
          }
          int gt = val[a] ^ val[x];
          for (int l = K - 1; l >= 0; l--) {
            if (basis[l]) {
              if ((gt ^ basis[l]) < gt) {
                gt ^= basis[l];
              }
            }
          }
          ans[b] = gt;
        }
      }
    }
  }
  printf("%d\n", ans[1]);
  return 0;
}
