N = int(input())
a_list = []
max_v = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]==max_v:
        max_ind.append(i)
del a_list[max_ind[-1]]
sec = max(a_list)
for i in range(N):
    if i in max_ind:
        print(sec)
    else:
        print(max_v)
        