#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 2e5 + 5;
int u[maxm], v[maxm], nextt[maxm], first[maxn], sign;
int w[maxm], n, m;
void addedge(int x, int y, int z) {
  u[++sign] = x;
  v[sign] = y;
  w[sign] = z;
  nextt[sign] = first[x];
  first[x] = sign;
}
struct LinearBase {
  long long place[105];
  long long cnt;
  LinearBase() { memset(place, 0, sizeof place); }
  void Insert(long long x) {
    for (int i = 63; ~i; i--) {
      if ((x >> i) & 1ll) {
        if (!place[i]) {
          place[i] = x;
          return;
        } else {
          x ^= place[i];
        }
      }
    }
  }
} lb;
int sum[maxn];
int book[maxn];
void dfs(int node, int val) {
  book[node] = 1;
  sum[node] = val;
  for (int i = first[node]; i; i = nextt[i]) {
    if (book[v[i]]) {
      lb.Insert(sum[node] ^ sum[v[i]] ^ w[i]);
      continue;
    }
    dfs(v[i], val ^ w[i]);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    addedge(x, y, z);
    addedge(y, x, z);
  }
  dfs(1, 0);
  long long ans = sum[n];
  for (int i = 63; ~i; i--) {
    ans = min(ans, ans ^ lb.place[i]);
  }
  cout << ans << endl;
  return 0;
}
