n=int(input())
a=[int(input()) for i in range(n)] 
m=a[0]

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)