#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

struct person {
    ll id;
    ll a;
    ll b;
};

ll check(ll N, ll start, ll end, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix) {
    if (end > 2 * N) {
        return 0;
    }
    if (end_fix[start] >= 0) {
        return 0;
    }
    if (start_fix[end] >= 0) {
        return 0;
    }
    if (start_fix[start] >= 0) {
        return 2;
    }
    if (end_fix[end] >= 0) {
        return 2;
    }
    if (start_end[start * 1000 + end] >= 0) {
        return 2;
    }
    return 1;
}

bool recursive1(ll N, ll start, ll cnt, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix, ll anypt, vector<ll>& memo) {
    //print(cnt, start);

    if (memo[start] >= anypt) {
        return false;
    }
    memo[start] = anypt;

    if (cnt == N) {
        return true;
    }
    if (start >= 2 * N) {
        return false;
    }
    for (ll end = start + 1; end <= min(start + N, 2 * N); end++) {
        bool success = true;
        ll anyy = anypt;
        for (ll ss = start; ss <= end - 1; ss++) {
            if (!success) {
                break;
            }
            ll ee = end - start + ss;
            ll result = check(N, ss, ee, start_end, start_fix, end_fix);
            // string rmsg = "success";
            // if (result == 0) {
            //     rmsg = "failure";
            // }
            // if (result == 1) {
            //     rmsg = "any";
            // }
            //print(rmsg, ss, ee, "check!");
            if (result == 0) {
                success = false;
            } else if (result == 1) {
                anyy--;
                if (anyy < 0) {
                    success = false;
                }
            } else {
                ;
            }
        }
        //print(start, end, success);
        if (success) {
            bool ok = recursive1(N, end + end - start, cnt + (end - start), start_end, start_fix, end_fix, anyy, memo);
            if (ok) {
                return true;
            }
        }
    }
    return false;
}

bool solve(ll N, vector<person>& persons) {
    set<ll> duplicate;
    for (auto p : persons) {
        if (p.a >= 0) {
            if (duplicate.count(p.a)) {
                return false;
            }
            duplicate.insert(p.a);
        }
        if (p.b >= 0) {
            if (duplicate.count(p.b)) {
                return false;
            }
            duplicate.insert(p.b);
        }
    }
    vector<ll> start_end(300000, -1);
    vector<ll> start_fix(300, -1);
    vector<ll> end_fix(300, -1);
    ll anypt = 0;
    for (auto p : persons) {
        if (p.a == -1 && p.b == -1) {
            anypt++;
        }
        if (p.a >= 0 && p.b == -1) {
            start_fix[p.a] = p.id;
        }
        if (p.a == -1 && p.b >= 0) {
            end_fix[p.b] = p.id;
        }
        if (p.a >= 0 && p.b >= 0) {
            start_end[p.a * 1000 + p.b] = p.id;
        }
    }
    vector<ll> memo(2 * N + 2, -1);
    return recursive1(N, 1, 0, start_end, start_fix, end_fix, anypt, memo);
}

int main() {
    ll N;
    cin >> N;

    vector<person> persons(N);
    for (ll i = 0; i < N; i++) {
        person p;
        cin >> p.a >> p.b;
        p.id = i;
        persons[i] = p;
    }
    if (solve(N, persons)) {
        print("Yes");
    } else {
        print("No");
    }
}

#include <bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define F first
#define S second
typedef long long ll;
typedef vector< int > vi;
typedef vector< ll > V;
typedef unordered_map<int, int > mp;
#define debug cout << -1 << endl;
#define REP(i, a, b) for(int i=a; i<b; i++)
#define pop pop_back
const ll MOD = 1000000007;
int cc = 1;
const int maxN = 2001;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void solve()
{
	int n;
	cin >> n;
	int arr[n];
	REP(i, 0, n) cin >> arr[i];
	int mnXOR = INT_MAX;
	for(int mask = 0; mask<(1<<n); mask++) {
		int ored = 0;
		int xored = 0;
		for(int i=0; i<n; i++) {
			ored |= arr[i];
			if(mask & (1<<i)) {
				xored ^= ored;
				ored = 0;
			}
		}
		xored ^= ored;
		mnXOR = min(mnXOR, xored);
	}
	cout << mnXOR << endl;
}

int main()
{
	FastIO;
	//freopen("tttt.in", "r", stdin);
	//freopen("tttt.out", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
