N = int(raw_input())
A = []
for i in range(0,N):
  A.append(int(raw_input()))
A = list(enumerate(A))
A = sorted(A, key=lambda x: x[1])
max_A = A[N-1][1]
second_max_A = A[N-2][1]
A = sorted(A,key=lambda x: x[0])
for i in range(0,N):
  if A[i][1] == max_A:
    print second_max_A
  else:
    print max_A
