#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long base = 10000007;   long long large = 1000000000000000000LL;   class UnionFind {    private:     vector<int> p, rank;       public:     UnionFind(int n) {       rank.assign(n, 0);       p.assign(n, 0);       for (int i = 0; i < n; i++) {         p[i] = i;       }     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;         } else {           p[x] = y;           if (rank[x] == rank[y]) {             rank[y]++;           }         }       }     }   };   vector<vector<pair<int, int> > > adj;   int n, m;   vector<pair<pair<int, int>, int> > e;   vector<int> dp;   void dfs(int u, int pa, int val) {     dp[u] = val;     for (int j = 0; j < (int)adj[u].size(); j++) {       int v = adj[u][j].first;       int d = adj[u][j].second;       if (v != pa) {         dfs(v, u, val ^ d);       }     }   }   int main() {     cin >> n >> m;     UnionFind uf(n);     adj.assign(n, vector<pair<int, int> >());     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       x--;       y--;       if (uf.isSameSet(x, y)) {         e.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), z));       } else {         uf.unionSet(x, y);         adj[x].push_back(pair<int, int>(y, z));         adj[y].push_back(pair<int, int>(x, z));       }     }     dp.assign(n, 0);     dfs(0, -1, 0);     vector<int> mask;     for (int i = 0; i < (int)e.size(); i++) {       int x = e[i].first.first;       int y = e[i].first.second;       int z = e[i].second;       int lo = dp[x] ^ dp[y] ^ z;       mask.push_back(lo);     }     int cur = 0;     for (int l = 30; l >= 0; l--) {       int c = -1;       for (int i = cur; i < (int)mask.size(); i++) {         if (mask[i] & (1 << l)) {           c = i;           break;         }       }       if (c == -1) continue;       swap(mask[cur], mask[c]);       for (int i = cur + 1; i < (int)mask.size(); i++) {         if (mask[i] & (1 << l)) mask[i] ^= mask[cur];       }       cur++;     }     vector<int> basis;     for (int i = 0; i < cur; i++) {       basis.push_back(mask[i]);     }     int l = 30;     int dis = dp[n - 1];     for (int i = 0; i < (int)basis.size(); i++) {       while (((1 << l) & basis[i]) == 0) l--;       if ((1 << l) & dis) dis ^= basis[i];     }     cout << dis << endl;     return 0;   }   