first = 1
second = 1
s = 0
n=int(input())
x = []
for i in range(0,n):
    s = int(input())
    if first <= s:
        second = first
        first = s
    if second <= s:
        second = s
    x.append(s)

for i in range(0,n):
    if x[i] == first:
        print(second)
    else:
        print(first)
    
    