#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n>=16){
        cout << (1<<16)-1 << '\n';
        return 0;
    }
    vector<bool> dp(1<<16, false);
    auto v = dp;
    dp[0] = true;
    rep(i,n){
        int a;
        cin >> a;
        auto dp2 = v;
        rep(j,16){
            rep(k,1<<16) if(dp[k]){
                dp2[a|k] = true;
            }
            a = (a >> 1) + (1 << 15) * (a & 1);
        }
        dp = dp2;
    }
    for(int i=(1<<16)-1;;i--){
        if(dp[i]){
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}