n = int(input())

a = []
for i in range(n):
	a.append(int(input()))

m = max(a)

aa = []
for i in range(n):
	if a[i] == m:
		aa.append(min(a))
	else:
		aa.append(a[i])
ma = max(aa)

for i in range(n):
	if a[i] == m:
		print(ma)
	else:
		print(m)
