import sys, re
input = sys.stdin.readline

n = int(input())
a = [int(input()) for x in range(n)]

temp_list = sorted(a)
m = temp_list[n-1]


for x in temp_list[::-1]:
  if x == m:
    continue
  else:
    m_dash = x
    break

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)