n = int(input())
a = [int(input()) for i in range(n)]
m = list(set(a))

for i in a:
    if i!=int(m[-1]):
        print(m[-1])
    elif a.count(m[-1]) > 1:
        print(m[-1])
    else:
        print(m[-2])
