#include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
#define mod 1000000007
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getLine(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int, int> a, pair<int, int> b) {
    double x = (double) a.first / a.second;
    double y = (double) b.first / b.second;
    return x < y;
}
long powUnderMod(long x, long y) {
    if(y == 0)return 1;
    long res = powUnderMod(x, y / 2) % mod;
    res = (res * res) % mod;
    if(y & 1)res = (res * x) % mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a, b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long n, m, f = 0, q, ans;
long tmp, flag = 0;


int main() {
///<editor-fold desc="ios">
    //IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in = 1, o;
    cin>>n;
    vector<long> v;
    double sum=0;
    for(int i = 0; i < n; ++i){
        cin>>tmp;
        v.push_back(tmp);
        sum+=tmp;
    }
    double avg=sum/2;
    sort(all(v));
    long mx=0;
    for(int i = v.size()-1; i >=0 ; --i){
        long count=0;
        for(int j = i; j >=0 ; --j){
            if(count+v[j]<=avg)count+=v[j];
        }
        mx=max(count,mx);
    }
    cout<<(long)sum-mx<<endl;



}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
#define rep(i,n) for (int i = 0; i < (n); ++i)


void solve(long long N, std::vector<long long> A){
    ll ans = 1E18;
    rep(i,1<<N){
        if(i == 0) continue;
        ll r = 0;
        vector<ll> d;
        rep(j,N){
            ll js = i >> j & 1;
            r |= A[j];
            if(js) {
                d.push_back(r);
                r = 0;
            }
        }
        if(~ i >> (N-1) & 1) d.push_back(r);
        ll t = d[0];
        for(ll j = 1; j<d.size(); j++){
            t ^= d[j];
        }
        ans = min(ans,t);
    }
    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}
