n = int(input())

a = [int(input()) for _ in range(n)]

ret = []
seta = set(a)
maxa1 = max(seta)
if len(seta) != 1:
    seta.remove(maxa1)
    maxa2 = max(seta)
else:
    maxa2 = maxa1

for i in range(n):
    if a[i] == maxa1:
        print(maxa2)
    else:
        print(maxa1)
