import copy

n = input("")
n = int(n)
suuaray = []
for i in range(n):
    num = input("")
    num = int(num)
    suuaray.append(num)

max_value = max(suuaray)
max_index = [i for i, x in enumerate(suuaray) if x == max_value]

suuaray.remove(max_value)
second_value = max(suuaray)

ans = []
for i in range(n):
    if i not in max_index:
        ans.append(max_value)
    else:
        ans.append(second_value)

for i in range(n):
    print(ans[i])