import copy

n = int( input() )

a = []
for i in range(n):
    a.append(int(input()))

tmp = copy.copy(a)
del tmp[0]
last_max = max(tmp)

print(last_max)
for i in range(1,n):
    if last_max == a[i]:
        tmp = copy.copy(a)
        del tmp[i]
        last_max = max(tmp)
    print(last_max)