n = int(input())
list = []
for i in range(n):
    list += [int(input())]

max = max(list)
for i in range(n):
    a = list[i]
    if a == max:
        del list[i]
        print(max(list))
        list.insert(i,a)
    else:
        print(max)