n = int(input())
a = []
mx1 = 0
mx2 = 0
for i in range(1,n+1):
    a.append(int(input()))
    if mx1 <= a[-1]:
        mx2 = mx1
        mx1 = a[-1]

for j in range(1,n+1):
    if a[j-1] == mx1:
        print(mx2)
    else:
        print(mx1)
