from collections import deque
n = int(input())
l = deque([int(input()) for _ in range(n)])
max_num = max(l)
m = deque([i for i in l if i != max_num])
second_num = max(m) if m else max_num

for i in l:
   if i == max_num:
       print(second_num)
   else:
       print(max_num)