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]
        ans = max(list)
        print(ans)
        list.insert(i,a)
    else:
        print(max_)
