#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#define endl '\n'

using namespace std;

long long dist[100005];
int br[(1<<14)+5];
int n;
vector<pair<int,long long>> v[100005];

void dfs(int i, int par) {
    for(auto &x : v[i]) {
        if(x.first==par) continue;
        dist[x.first]=dist[i]^x.second;
        dfs(x.first, i);
    }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n-1; i++) {
        int a,b; long long w; cin >> a >> b >> w;
        v[a].push_back({b, w});
        v[b].push_back({a, w});
    }
    dfs(1, -1);

    for(int i = 1; i <= n; i++) br[dist[i]]++;

    for(int xr = (1<<13); xr >= 0; xr--) {
        for(int i = 1; i <= n; i++) {
            if(br[dist[i]^xr]) {
                cout << xr;
                return 0;
            }
        }
    }

}