Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \operatorname{max}_{i = 1}^{k} x_{i}$.

The lucky number of the sequence of distinct positive integers x_1, x_2, ..., x_{k} (k > 1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.

You've got a sequence of distinct positive integers s_1, s_2, ..., s_{n} (n > 1). Let's denote sequence s_{l}, s_{l} + 1, ..., s_{r} as s[l..r] (1 ≤ l < r ≤ n). Your task is to find the maximum number among all lucky numbers of sequences s[l..r].

Note that as all numbers in sequence s are distinct, all the given definitions make sence.


-----Input-----

The first line contains integer n (1 < n ≤ 10^5). The second line contains n distinct integers s_1, s_2, ..., s_{n} (1 ≤ s_{i} ≤ 10^9).


-----Output-----

Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].


-----Examples-----
Input
5
5 2 1 4 3

Output
7

Input
5
9 8 3 5 7

Output
15



-----Note-----

For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2].

For the second sample you must choose s[2..5] = {8, 3, 5, 7}.

Difficulty: competition

Starter code:

Solutions:
def maximum_xor_secondary(sequence):
    stack, answer = [], 0
    for x in sequence:
        while stack:
            answer = max(answer, stack[-1] ^ x)
            if stack[-1] > x:
                break
            else:
                stack.pop()
        stack.append(x)

    return answer


size, num = input(), [int(x) for x in input().split()]


print(maximum_xor_secondary(num))





# Made By Mostafa_Khaled


n = int(input())
Ar = [int(x)for x in input().split()]
stack = []
ans = 0
for i in range(0,n):
    while(len(stack)!=0):
        if(stack[-1]<Ar[i]):
            ans = max(ans,stack[-1]^Ar[i])
            stack.pop()
        else:
            ans = max(ans,stack[-1]^Ar[i])
            break
    stack.append(Ar[i])
print(ans)


RI = lambda : [int(x) for x in input().split()]
rw = lambda : [input().strip()]
n=int(input())
l=RI()

stack=[]
index_stack=-1

maxo=0
i=0
while(i<n):
    if(index_stack==-1 or stack[index_stack]>l[i]):
        stack.append(l[i])
        index_stack+=1
        i+=1
    else:
        #print(stack[index_stack],end=" ")
        #print(l[i])
        maxo=max(stack[index_stack]^l[i],maxo)
        temp=stack[index_stack]

        stack.pop()
        index_stack-=1

        
        if(len(stack)!=0):
            #print(stack[index_stack],end=" ")
            #print(stack[index_stack])
            maxo=max(temp^stack[index_stack],maxo)

while(len(stack)!=1):
    temp=stack[index_stack]
    
    stack.pop()
    index_stack-=1

    #print(stack[index_stack],end=" ")
    #print(stack[index_stack])
    maxo=max(temp^stack[index_stack],maxo)
print(maxo)


n=int(input())
a=[int(n) for n in input().split()]
stack=[]
maxx=0
i=0
while i<n:
    if not stack or a[i]<stack[-1]:
        stack.append(a[i])
        i+=1
    else:
        maxx=(max(stack[-1]^a[i],maxx))
        temp=stack.pop()
        if stack:
            maxx=max(stack[-1]^temp,maxx)
    #print(stack)
while len(stack)!=1:
    temp=stack.pop()
    maxx=max(temp^stack[-1],maxx)
print(maxx)

n = int(input())
nl = [int(x) for x in input().split()]
st = []
ans = 0
for x in nl:
    if st and st[-1] > x:
        ans = max(ans, st[-1]^x)
    elif st:
        while st and st[-1] < x:
            ans = max(ans, st.pop()^x)
        if st:
            ans = max(ans, st[-1]^x)
    st.append(x)
print(ans)


#!/usr/bin/env python
# coding: utf-8

# In[5]:


from collections import deque

stack=deque()
n=int(input())
a=list(map(int,input().split()))
res1=0
l=0

for i in a:
    while stack and stack[-1]<i:
        stack.pop()
        l-=1
        
    stack.append(i)
    l+=1
    
    if l>1:
        res1=max(res1,stack[-1]^stack[-2])
        
        
stack.clear()
l=0
res2=0
a.reverse()

for i in a:
    while stack and stack[-1]<i:
        stack.pop()
        l-=1
        
    stack.append(i)
    l+=1
    
    if l>1:
        res2=max(res2,stack[-1]^stack[-2])
        

        
print(max(res1,res2))


# In[ ]:






import sys
#t = -1
# def input():
#     nonlocal t
#     t += 1
#     return data[t]
#data=sys.stdin.readlines()
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
m=0
for i in range(1,n):
    if len(b)>0:
        m = max(m, b[-1] ^ a[i])
    while len(b)>0 and a[i]>b[-1]:
        m = max(m, b[-1] ^ a[i])
        b.pop()
    if len(b)>0:
        m = max(m, b[-1] ^ a[i])
    b.append(a[i])
    #print(b)
print(m)




def xor(a, b):
  return a ^ b

def solve(l):
    ans = xor(l[0], l[1])
    st = [l[0], l[1]]

    for i in range(2, n):
      while len(st) > 0 and st[-1] < l[i]:
        st.pop()
      st.append(l[i])
      if len(st) >= 2:
         ans = max(ans, xor(st[-1], st[-2]))
    return ans

n = int(input())
l = input()
l = [int(i) for i in l.split()]


ans = solve(l)

l.reverse()

ans = max(ans, solve(l))

print(ans)


'''
    Auther: ghoshashis545 Ashis Ghosh
    College: Jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return list(map(int,input().split()))
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')



def solve():
    
    
    n=ii()
    a=li()
    b=[]
    for j in range(31,-1,-1):
        for i in range(n):
            if (a[i]>>j)&1:
                b.append(i)
        if(len(b)<n and len(b)>0):
            break
        b=[]
        
    
        
    if len(b)==n or len(b)==0:
        print(0)
        return
        
    ans=0
    x=0
    
    for j in range(len(b)-1):
        
        mx=0
        x1=a[b[j]]
        for i in range(b[j]-1,x-1,-1):
            mx=max(mx,a[i])
            ans=max(ans,x1^mx)
        mx=0
        for i in range(b[j]+1,b[j+1]):
            mx=max(mx,a[i])
            ans=max(ans,x1^mx)
        x=b[j]+1
    
    
       
    mx=0
    x1=a[b[len(b)-1]]
    for i in range(b[len(b)-1]-1,x-1,-1):
        mx=max(mx,a[i])
        ans=max(ans,x1^mx)
    
    mx=0
    for i in range(b[len(b)-1]+1,n):
            mx=max(mx,a[i])
            ans=max(ans,x1^mx)
            
    print(ans)
    
    
    
    
    
    
    
    
def __starting_point():
    
    solve()
    

__starting_point()

def fun(numbers):
    # numbers.sort(reverse=True)
    le = len(numbers)
    stack =[]
    ans=0
    i=1
    for i in numbers:
        while stack:
            ans  = max(ans,stack[-1]^i)
            if stack[-1] > i:
                break
            else:
                stack.pop()
        stack.append(i)
    
    return ans


# var1, var2,var3 = [int(x) for x in input().split()]
n = input()
user_input = input().split(' ')
numbers = [int(x.strip()) for x in user_input] 
# st = input()
# print(fun(st))

print(fun(numbers))





# # st = input()
# var1, var2 = [int(x) for x in input().split()]

# # # fun(st,var1,var2)

# # # var2 = input()
# print(fun(var1,var2))

# ############################################################3###############################

# # user_input = input().split(' ')
# # numbers = [int(x.strip()) for x in user_input] 
# # print(fun(numbers))
# ######################################################################################