#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6 + 7;
const int maxlog = 21;
vector<pair<int, int>> g[maxn];
int h[maxn];
int pref[1 << 21];
int cnt[1 << 21];
void dfs(int u, int xorr, int par)
{
    cnt[xorr]++;
    h[u] = xorr;
    for (auto x : g[u])
    {
        if (x.first == par)
            continue;
        dfs(x.first, xorr ^ x.second, u);
    }
    return;
}
int n;

inline bool check(int xorr, int pos)
{
    int num = (1LL << maxlog) - (1LL << pos);

    for (int i = 1; i <= n; i++)
    {
        int lowbound = ((h[i] & num) ^ xorr);
        int highbound = lowbound + (1LL << pos) - 1;
        int ans = pref[highbound];
        if (lowbound - 1 >= 0)
            ans -= pref[lowbound - 1];
        if (ans >= 1)
        {
            return true;
        }
    }
    return false;
}
signed main()
{

    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        g[a].push_back({b, w});
        g[b].push_back({a, w});
    }
    dfs(1, 0, -1);
    for (int i = 1; i < (1 << 21); i++)
    {
        pref[i] += pref[i - 1] + cnt[i];
    }
    int maxor = 0;
    for (int i = maxlog - 1; i >= 0; i--)
    {
        maxor += (1LL << i);
        if (!check(maxor, i))
        {
            maxor -= (1LL << i);
        }
    }
    cout << maxor << endl;

    return 0;
}
