#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const long long mod = 1e9 + 31;
mt19937 mtrand(time(0));
int n, m;
struct Linear_Basis {
  static const int base = 31;
  long long p[base], np[base], cnt;
  void init() {
    cnt = 0;
    memset(p, 0, sizeof(p));
    memset(np, 0, sizeof(np));
  }
  bool ins(long long x) {
    for (int i = base - 1; i >= 0; --i) {
      if ((x >> i) & 1) {
        if (p[i])
          x ^= p[i];
        else {
          ++cnt;
          p[i] = x;
          break;
        }
        if (!x) break;
      }
    }
    return x > 0;
  }
  long long querymin(long long x) {
    for (int i = base - 1; i >= 0; --i) {
      if ((x >> i) & 1) x ^= p[i];
    }
    return x;
  }
  long long querymax(long long x) {
    for (int i = base - 1; i >= 0; --i) {
      if (!((x >> i) & 1)) x ^= p[i];
    }
    return x;
  }
  long long askmax() {
    long long res = 0;
    for (int i = base - 1; i >= 0; --i) {
      res = max(res, res ^ p[i]);
    }
    return res;
  }
  long long askmin() {
    for (int i = 0; i < base; ++i) {
      if (p[i]) return p[i];
    }
  }
  void rebuild() {
    cnt = 0;
    for (int i = 0; i < base; ++i) {
      long long tp = p[i];
      for (int j = i - 1; j >= 0; --j) {
        if ((tp >> j) & 1) tp ^= p[j];
      }
      if (tp) np[cnt++] = tp;
    }
  }
  long long askkth(long long k) {
    if (!cnt || k >= (1ll << cnt)) return -1;
    long long res = 0;
    for (int i = 0; i < cnt; ++i) {
      if ((k >> i) & 1) {
        res ^= np[i];
      }
    }
    return res;
  }
  void margeLB(Linear_Basis &a) {
    for (int i = base - 1; i >= 0; --i) {
      if (a.p[i]) ins(a.p[i]);
    }
  }
} LB;
vector<pair<int, int> > vec[mx];
int dep[mx], vis[mx];
void dfs(int u, int fa) {
  vis[u] = 1;
  for (pair<int, int> it : vec[u]) {
    if (it.first != fa) {
      if (!vis[it.first]) {
        dep[it.first] = dep[u] ^ it.second;
        dfs(it.first, u);
      } else {
        LB.ins(dep[u] ^ dep[it.first] ^ it.second);
      }
    }
  }
}
int main() {
  int u, v, w;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    vec[u].push_back(make_pair(v, w));
    vec[v].push_back(make_pair(u, w));
  }
  LB.init();
  dfs(1, 0);
  cout << LB.querymin(dep[n]) << endl;
}
