n=int(input())
a=int(input())
f,v,w=0,a,a
for i in range(1,n):
    a=int(input())
    if a>=v:
        w,v,f=v,a,i
    elif a>=w:
        w=a
for i in range(n):
    if i==f:
        print(w)
    else:
        print(v)