N = int(input())
a =int(input())
b=int(input())
if a>b:
    max1 = a
    max2 = b
else:
    max1 = b
    max2 = a
list = []
list.append(a)
list.append(b)
#print(max1,max2)                                                              
for _ in range(N-2):
    i = int(input())
    list.append(i)
    if i > max1:
        max2 = max1
        max1 = i
    elif i > max2 and i!=max1:
        max2 = i
#print(max1,max2)                                                              
if max2 == 0:
    max2 = max1
for i in list:
    if i == max1:
        print(max2)
    else:
        print(max1)