import itertools
import math
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
maxa = max(a)

b=[]
for i in range(n):
    b.append(a[i])
    if b[i] == maxa:
        b[i] = 0
maxb = max(b)

for i in range(n):
    if maxa !=  a[i]:
        print(maxa)
    else:
        print(maxb)