#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

sa = sorted(a)
sa.reverse()

ma = sa[0]
mi = sa[0]
for i in sa:
    if i != mi:
        mi = i

for x in sa:
    if i == ma:
        print(mi)
    else:
        print(ma)

