// editor4
def is_triangle(a, b, c):
    return a + b > c and a + c > b and b + c > a

def piccolo_energy():
    try:
        K = int(input().strip())
        if K < 4 or K > 10:
            print("Invalid input")
            return
        
        values = list(map(int, input().split()))
        
        if len(values) != K or any(v < 1 or v >= 99 for v in values):
            print("Invalid input")
            return
        
        stack = []
        preserved = set()
        
        for v in values:
            stack.append(v)
            # Check triplets from stack
            for i in range(len(stack)):
                for j in range(i+1, len(stack)):
                    for k in range(j+1, len(stack)):
                        a, b, c = stack[i], stack[j], stack[k]
                        if is_triangle(a, b, c):
                            preserved.update([a, b, c])
        
        if preserved:
            print(max(preserved))
        else:
            print(-1)
    
    except:
        print("Invalid input")

# Example run
# Input:
# 6
# 4 5 6 7 8 9
# Output: 9
piccolo_energy()