import numpy as np

N = int(input())

A = np.array([])

for i in range(N):
	a = int(input())
	A = np.hstack( (A,a) )


B = A
ans = np.amax(A)
j = np.argmax(A)
ans2 = np.amax(np.delete(A,j))

for i in range(N):
	if i == j:
		ans = ans2
	print(int(ans))
