n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)

for j in a:
    if j==m and a.count(m)>1:
        print(m)
    elif j==m and a.count(m)==1:
        print(m2)
    else:
        print(m)