#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0; i <(n); i++)
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 1<<30;
    rep(s,1<<(n-1)){
        int now = 0;
        int o = 0;
        rep(i,n){
            o |= a[i];
            if(s>>i&1){
                now ^= o;
                o = 0;
            }
        }
        now ^= o;
        ans = min(ans,now);
    }
    cout << ans;
}
   
#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N), B(N);
    for(auto&& i : A)cin >> i;
    for(auto&& i : B)cin >> i;
    priority_queue<unsigned long> pq;
    reverse(begin(A), end(A));
    unsigned long ans{0};
    for(unsigned long i{0}; i < N; ++i){
        pq.emplace(A.back());
        pq.emplace(B.back());
        A.pop_back();
        B.pop_back();
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}