import numpy as np

n = int(input())
a = np.array([int(input()) for i in range(n)])

amax_i = np.argmax(a)
if amax_i == n-1:
    b = a[:amax_i]
else:
    b = np.hstack([a[:amax_i], a[amax_i+1]])
bmax = np.max(b)

for i in range(n):
    if i == amax_i:
        print(bmax)
    else:
        print(a[amax_i])