#include <iostream>
#include <vector>
#include <unordered_map>
#define endl '\n'

using namespace std;

long long dist[100005];
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);

    unordered_map<long long, bool> m;
    long long mask=0, mask1=0;
    for(int j = 60; j >= 0; j--) {
        m.clear();
        mask1=((1LL<<61)-1)-((1LL<<j)-1);
        for(int i = 1; i <= n; i++) m[dist[i]&mask1]=1;
        for(int i = 1; i <= n; i++) {
            if(m[(dist[i]&mask1)^(mask|(1LL<<j))]) {
                mask|=(1LL<<j);
                break;
            }
        }
    }
    cout<<mask<<endl;
}