n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max1 = 0
max2 = 0
for j in a:
    if j >= max1:
        max2 = max1
        max1 = j

for k in a:
    if max1 == k:
        print(max2)
    else:
        print(max1)
