n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
for i in range(n):
  for j in range(i-1,0):
    for k in range(i+1,n):
      ans1 = max(a[j],a[k])
      ans = max(0,ans1)
      print(ans)
b=0
for i in range(n-1):
  b = max(a[i],a[i+1])
  ans2 = max(b,0)
print(b)