n = int(input())
v = [int(input()) for i in range(n)]

v_max = max(v)
flag = 0
for i in range(n):
    if v[i] == v_max:
        flag = 1
    elif flag == 1:
        print(v_max)
        flag = 1
    elif flag == 0:
        v_i = v[:]
        del v_i[i]
        print(max(v))