Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers. 

The value of a non-empty subsequence of k elements of a is defined as ∑ 2^i over all integers i ≥ 0 such that at least max(1, k - 2) elements of the subsequence have the i-th bit set in their binary representation (value x has the i-th bit set in its binary representation if ⌊ (x)/(2^i) ⌋ mod 2 is equal to 1). 

Recall that b is a subsequence of a, if b can be obtained by deleting some(possibly zero) elements from a.

Help Ashish find the maximum value he can get by choosing some subsequence of a.

Input

The first line of the input consists of a single integer n (1 ≤ n ≤ 500) — the size of a.

The next line consists of n space-separated integers — the elements of the array (1 ≤ a_i ≤ 10^{18}).

Output

Print a single integer — the maximum value Ashish can get by choosing some subsequence of a.

Examples

Input


3
2 1 3


Output


3

Input


3
3 1 4


Output


7

Input


1
1


Output


1

Input


4
7 7 1 1


Output


7

Note

For the first test case, Ashish can pick the subsequence \{{2, 3}\} of size 2. The binary representation of 2 is 10 and that of 3 is 11. Since max(k - 2, 1) is equal to 1, the value of the subsequence is 2^0 + 2^1 (both 2 and 3 have 1-st bit set in their binary representation and 3 has 0-th bit set in its binary representation). Note that he could also pick the subsequence \{{3\}} or \{{2, 1, 3\}}.

For the second test case, Ashish can pick the subsequence \{{3, 4\}} with value 7.

For the third test case, Ashish can pick the subsequence \{{1\}} with value 1.

For the fourth test case, Ashish can pick the subsequence \{{7, 7\}} with value 7.
#include <bits/stdc++.h>
using namespace std;
bool primecheck(long long int a) {
  bool check = true;
  if (a == 1) return (false);
  for (long long int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      check = false;
      break;
    }
  }
  return (check);
}
vector<long long int> primeFactors(long long int n) {
  vector<long long int> sol;
  bool once = false;
  while (n % 2 == 0) {
    if (!once) {
      sol.push_back(2);
      once = true;
    }
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    bool once = false;
    while (n % i == 0) {
      if (!once) {
        sol.push_back(i);
        once = true;
      }
      n = n / i;
    }
  }
  if (n > 2) {
    sol.push_back(n);
  }
  return (sol);
}
vector<long long int> printDivisors(long long int n) {
  vector<long long int> sol;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i) {
        sol.push_back(i);
      } else {
        sol.push_back(i);
        sol.push_back(n / i);
      }
    }
  }
  return (sol);
}
long long int digits(long long int a) { return (floor(log10(a)) + 1); }
long long int bits(long long int n) { return __builtin_popcount(n); }
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
void addEdge(vector<long long int> adj[], long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
vector<long long int> path;
void dfs(long long int u, vector<long long int> adj[], vector<bool> &visited,
         long long int parent = -1) {
  visited[u] = true;
  path[u] = parent;
  for (long long int i = 0; i < adj[u].size(); i++) {
    if (visited[adj[u][i]] == false) {
      dfs(adj[u][i], adj, visited, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, c, i, j, k, l, m, n, t, p;
  cin >> a;
  long long int arr[a];
  for (i = 0; i < a; i++) cin >> arr[i];
  long long int maxie = 0;
  for (i = 0; i < a && i < 3; i++) {
    maxie |= arr[i];
  }
  for (i = 0; i < a - 2; i++) {
    for (j = i + 1; j < a - 1; j++) {
      for (k = j + 1; k < a; k++) {
        long long int val = (arr[i] | arr[j]) | arr[k];
        maxie = max(val, maxie);
      }
    }
  }
  cout << maxie << "\n";
}
