N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
B = sorted(set(A), key = A.index)
B = sorted(B, reverse = True)
max_A = B[0]
try:
  second_max = B[1]
except:
  second_max = B[0]
for i in range(N):
  if A[i] == max_A:
    print(second_max)
  else:
    print(max_A)