n = int(input())
l = [0]*n
s = []
f_max,s_max = 0,0
for i in range(n):
    a = int(input())
    l[i] = a
    
    if a not in s:
        s.append(a)

    if f_max < a:
        s_max = f_max
        f_max = a
    elif s_max < a < f_max:
        s_max = a

s.sort()

if len(set(l))==1:
    for i in range(n):
        print(f_max)
    exit()

for i in range(n):
    """if l[i]==f_max:
        print(s_max)
    else:
        print(f_max)"""
    if l[i]==s[-1]:
        print(s[-2])
    else:
        print(s[-1])

