#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6 + 7;
const int maxlog = 21;
int h[maxn];
int pref[1 << 21];
int xorpref[maxn];
int cnt[1 << 21];
int n;

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

    for (int i = 1; i <= n; i++)
    {
        int lowbound = ((xorpref[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;
        xorpref[b] = xorpref[a] ^ w;
        cnt[xorpref[b]]++;
    }
    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;
}
