#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()

m1 = sa[0]
m2 = sa[0]
for i in sa:
    if i != m1:
        m2 = i
        break

for i in a:
    if i == m1:
        print(m2)
    else:
        print(m1)

