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 CMP(int a, int b) { return a > b; }
long long int p = 1e9 + 7;
long long int power2(long long int n) {
  long long int res = 1;
  for (long long int i = 1; i <= n; i++) res *= 2;
  return res;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int cnt1 = 0, u, cnt = 0, n;
vector<vector<long long int>> adj1(200010);
vector<pair<long long int, long long int>> adj[200010];
vector<long long int> wt(200010);
long long int visi[310068], vis[300100], last1[10000];
vector<long long int> viso;
bool ok = false;
long long int m, ans = 0;
long long int dp[200010];
bool mycompare(pair<long long int, string> p, pair<long long int, string> t) {
  if (p.first == t.first && p.second < t.second)
    return true;
  else if (p.first == t.first && p.second > t.second)
    return false;
  else if (p.first < t.first)
    return false;
  else if (p.first > t.first)
    return true;
  else
    return false;
}
long long int maxi = 1e7;
set<long long int> w;
pair<long long int, long long int> rotate(long long int x, long long int y,
                                          long long int a, long long int b,
                                          long long int t) {
  long long int i;
  for (i = 0; i < t; i++) {
    long long int p = a + b - y, q = x + b - a;
    x = p, y = q;
  }
  pair<long long int, long long int> P = make_pair(x, y);
  return P;
}
long long int dist(long long int x1, long long int y1, long long int x2,
                   long long int y2) {
  long long int d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  return d;
}
bool check(long long int x1, long long int y1, long long int x2,
           long long int y2, long long int x3, long long int y3,
           long long int x4, long long int y4) {
  long long int d2 = dist(x1, y1, x2, y2);
  long long int d3 = dist(x1, y1, x3, y3);
  long long int d4 = dist(x1, y1, x4, y4);
  if (d2 == 0 || d3 == 0 || d4 == 0) return false;
  if (d2 == d3 && d4 == 2 * d2 &&
      2 * dist(x2, y2, x4, y4) == dist(x2, y2, x3, y3))
    return true;
  if (d3 == d4 && d2 == 2 * d3 &&
      2 * dist(x2, y2, x3, y3) == dist(x3, y3, x4, y4))
    return true;
  if (d2 == d4 && d3 == 2 * d2 &&
      2 * dist(x2, y2, x3, y3) == dist(x2, y2, x4, y4))
    return true;
  return false;
}
long long int A[20010];
class SegmentTree {
 public:
  vector<long long int> A;
  vector<long long int> tree;
  long long int n, d;
  SegmentTree(vector<long long int> &inp, long long int depth) {
    A = inp;
    d = depth;
    n = A.size();
    tree.resize(4 * n);
    build(1, 0, n - 1, d);
  }
  void build(long long int node, long long int start, long long int end,
             long long int depth) {
    if (start == end)
      tree[node] = A[start];
    else {
      long long int mid = (start + end) / 2;
      build(2 * node, start, mid, depth - 1);
      build(2 * node + 1, mid + 1, end, depth - 1);
      if (depth % 2 == 1)
        tree[node] = tree[2 * node] | tree[2 * node + 1];
      else
        tree[node] = tree[2 * node] ^ tree[2 * node + 1];
    }
  }
  void update(long long int node, long long int start, long long int end,
              long long int idx, long long int depth) {
    if (start == end) {
      tree[node] = A[start];
    } else {
      long long int mid = (start + end) / 2;
      if (start <= idx && idx <= mid)
        update(2 * node, start, mid, idx, depth - 1);
      else
        update(2 * node + 1, mid + 1, end, idx, depth - 1);
      if (depth % 2 == 1)
        tree[node] = tree[2 * node] | tree[2 * node + 1];
      else
        tree[node] = tree[2 * node] ^ tree[2 * node + 1];
    }
  }
  long long int update(long long int index, long long int value) {
    A[index] = value;
    update(1, 0, n - 1, index, d);
    return tree[1];
  }
};
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int>>,
               greater<pair<long long int, long long int>>>
    pq;
void dj(long long int s) {
  pair<long long int, long long int> pi;
  for (long long int i = 0; i < adj[s].size(); i++) {
    if (vis[adj[s][i].first] > vis[s] + adj[s][i].second) {
      vis[adj[s][i].first] = vis[s] + adj[s][i].second;
      visi[adj[s][i].first] = s;
      pq.push(make_pair(vis[adj[s][i].first], adj[s][i].first));
    }
  }
  if (pq.empty()) return;
  pi = pq.top();
  pq.pop();
  dj(pi.second);
}
void path(long long int x) {
  if (x == 0) return;
  path(visi[x]);
  cout << x << " ";
}
bool note(pair<long long int, long long int> p,
          pair<long long int, long long int> s) {
  if (p.second != s.second && p.first < s.first)
    return true;
  else
    return false;
}
bool isPowerOfTwo(long long int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
int check(int i, int j, int n, int m) {
  if (i >= 0 && i < n && j < m && j >= 0) return 1;
  return 0;
}
int main() {
  long long int n;
  cin >> n;
  long long int i, j, k, ans = INT_MIN;
  long long int a[n + 1];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++)
    for (j = i; j < n; j++)
      for (k = j; k < n; k++) {
        ans = max(ans, (a[i] | a[j] | a[k]));
      }
  cout << ans << endl;
}
