import heapq

num = int(input())
a = [int(input()) for i in range(num)]
b = heapq.nlargest(2, a)
c = [b[0] for i in range(num)]
if b[0] == b[1]:
  for j in c:
    print(j)
else:
  for f in range(num):
    if f == a.index(b[0]):
      print(b[1])
    else:
      print(b[0])

