import heapq

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

list_ans = list_score.copy()
list_ans.sort()
heapq.heapify(list_ans)

for i in range(n):
    a = list_score[i]
    list_ans.remove(a)
    print(list_ans[-1])
    heapq.heappush(list_ans, a)