#include using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < n; i++) #define rrep(i,n) for (int i = (n) - 1; i >= 0; i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int n, A[200010]; int shift(int x){ return x / 2 + (x % 2) * (1 << 15); } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n; rep(i, n){ cin >> A[i]; } if (n >= 16){ cout << (1 << 16) - 1 << "\n"; } else{ vector> dp(n + 1, vector(1 << 16)); dp[0][0] = true; rep(i, n){ rep(j, 1 << 16){ if (!dp[i][j]){ continue; } int x = A[i]; rep(k, 16){ dp[i + 1][j | x] = true; x = shift(x); } } } rrep(i, 1 << 16){ if (dp[n][i]){ cout << i << "\n"; return 0; } } } }