import time
import numpy as np
t1 = time.time()
n = int(input())
a = [int(input()) for i in range(n)]

t2 = time.time()
b = np.array([max(set(a[:x]+a[x+1:])) for x in range(len(a))])

c = b.reshape(n,1)

print(c)

t3 = time.time()
'''
s = str()
for i in b:
	s += str(i)+'\n'
	
print(s)
'''
#t4 = time.time()
'''
print(t2-t1)
print(t3-t2)
print(t4-t3)
'''