#include <bits/stdc++.h>
using namespace std;
class Gauss_Elimin {
 private:
  vector<vector<bool>> v;
  vector<bool> ans;
  int n;
  void xor_line(int l1, int l2) {
    for (int i(0); i < n; i++) v[l1][i] = v[l1][i] ^ v[l2][i];
  }
  void clean_last_line() {
    for (int i(0); i < v.size() - 1; i++) {
      int p(0);
      while (p < n && !v[i][p]) p++;
      if (p < n && v.back()[p]) xor_line(v.size() - 1, i);
    }
  }
  void get_ans(int l) {
    if (l == -1) return;
    bool act(v[l][n - 1]);
    int p(0);
    while (p < n && !v[l][p]) p++;
    if (p == n) {
      get_ans(l - 1);
      return;
    }
    for (int i(n - 2); i > p; i--)
      if (ans[i] && v[l][i]) act ^= 1;
    ans[p] = act;
    get_ans(l - 1);
  }

 public:
  Gauss_Elimin() {}
  Gauss_Elimin(int _n) : n(_n), ans(vector<bool>(_n)) {}
  vector<bool> get_ans() {
    get_ans(v.size() - 1);
    return ans;
  }
  bool add_restriction(vector<bool> restr) {
    v.push_back(restr);
    clean_last_line();
    int p(0);
    while (p < n && !v.back()[p]) p++;
    if (p == n - 1) v.pop_back();
    return (p != n - 1);
  }
} gauss;
long long xortotal;
long long v[2000010];
int n, cnt;
int h[100010];
void try_add_restriction(int bit, int act);
vector<pair<int, int>> adia[100010];
bool viz[100010];
int xoract[100010];
void dfs(int nod, int tata = 0);
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a, b, w;
  while (m--) {
    cin >> a >> b >> w;
    adia[a].push_back({b, w});
    if (b != a) adia[b].push_back({a, w});
  }
  dfs(1);
  gauss = Gauss_Elimin(cnt + 1);
  int nrxor = xoract[n];
  for (int i(30); i >= 0; i--) try_add_restriction(i, nrxor & (1 << i));
  vector<bool> ans = gauss.get_ans();
  for (int i(0); i < cnt; i++) {
    if (ans[i]) nrxor ^= v[i];
  }
  cout << nrxor;
  return 0;
}
void dfs(int nod, int tata) {
  viz[nod] = 1;
  for (auto i : adia[nod]) {
    if (i.first == tata) continue;
    if (i.first == nod)
      v[cnt++] = i.second;
    else if (viz[i.first]) {
      v[cnt++] = xoract[nod] ^ xoract[i.first] ^ i.second;
    } else {
      h[i.first] = 1 + h[nod];
      xoract[i.first] = xoract[nod] ^ i.second;
      dfs(i.first, nod);
    }
  }
}
void try_add_restriction(int bit, int act) {
  vector<bool> restr(cnt + 1, 0);
  restr.back() = (act ? 1 : 0);
  bool ok(0);
  for (int i(0); i < cnt; i++)
    if (v[i] & (1ll << bit)) restr[i] = 1, ok = 1;
  if (!ok) return;
  gauss.add_restriction(restr);
}
