N = int(input())
A = [int(input()) for i in range(N)]

maxval = -999
second = -999
maxidx = -999
for idx, val in enumerate(A):
    if val > maxval:
        second = maxval
        maxval = val
        maxidx = idx

for i in range(N):
    if i == maxidx:
        print(second)
    else:
        print(maxval)