n = int(input())
a = [int(input()) for i in range(n)]
mx = a[0]
sec = 0
for i in a:
    if i>=mx:
        sec = mx
        mx = i
    elif i>sec:
        sec = i
for i in a:
    if i==mx:
        print(sec)
    else:
        print(mx)