n = int(input())
l=[int(input()) for x in range(n)]
setl=list(set(l))
m=max(l)
if len(setl)==1:
    print(m)
    exit()
else:
    second=setl[-2]
for i in range(n):
    if l[i]==m:
        print(second)
    else:
        print(m)