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.
import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static char[][] arr;
    static boolean[][] access;
    public static long gcf(long x, long y) {
        while(x%y!=0 && y%x!=0) {
            if(x>y)
                x%=y;
            else
                y%=x;
        }
        return x>y? y:x;
    }
    static int ceildiv(int x, int y){
        return x%y==0? x/y: x/y+1;
    }
    static long pow(long a, long pow){
        long ans=1;
        while(pow>0){
            if((pow&1)==1)
                ans*=a;
            a*=a;
            pow>>=1;
        }
        return ans;
    }
    static int prime(int x) {
        for(int i=2; i<=x/i; i++) {
            if(x%i==0)
                return x/i;
        }
        return 1;
    }
    static boolean valid(int i, int j){
        return i<arr.length && i>=0 && j<arr[0].length && j>=0;
    }
    static void dfs(int i, int j){
        access[i][j]=true;
        for(int k=0; k<4; k++){
            if(valid(i+dx[k], j+dy[k]) && arr[i+dx[k]][j+dy[k]]!='#' && !access[i+dx[k]][j+dy[k]]){
                    dfs(i+dx[k], j+dy[k]);
            }
        }
    }
    static int[] dx={1,-1,0,0};
    static int[] dy={0,0,1,-1};
    static boolean valid(){
        int n=arr.length, m=arr[0].length;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if((arr[i][j]=='G' && !access[i][j]) || (arr[i][j]=='B' && access[i][j]))
                    return false;
            }
        }
        return true;
    }
    static boolean containsgood(char[][] arr){
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<arr[0].length; j++)
                if(arr[i][j]=='G')
                    return false;
        }
        return true;
    }
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        if(n>3){
            long[] arr=new long[n];
            for(int i=0; i<n; i++)
                arr[i]=sc.nextLong();
            long ans=0l;
            for(int i=0; i<n; i++){
                for(int j=i+1; j<n; j++){
                    for(int k=j+1; k<n; k++)
                        ans=Math.max(ans, arr[i]|arr[j]|arr[k]);
                }
            }
            pw.println(ans);
        }else{
            long ans=0l;
            while(n-->0)
                ans|=sc.nextLong();
            pw.println(ans);
        }
        pw.close();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.y!=other.y){
                return other.y-this.y;
            }else{
                return (this.x-other.x);
            }
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x == p.x;
        }
        public boolean equal(Pair p){
            return this.x==p.x && this.y==p.y;
        }
    }
    static class tuple implements Comparable<tuple>{
        int x;int y;int z;
        public tuple(int x, int y, int z){
            this.x=x;
            this.y=y;
            this.z=z;
        }
        public int compareTo(tuple other) {
            if(this.x!=other.x)
                return this.x-other.x;
            else {
                if(this.y!=other.y)
                    return this.y-other.y;
                else
                    return this.z-other.z;
            }
        }
        public boolean equal(tuple t){
            return this.x==t.x && this.y==t.y;
        }
    }
}
