import heapq
n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
heap = []
for ai in ais:
	heapq.heappush(heap, ai)
	if len(heap) == 3: 
		heapq.heappop(heap)

u,v = heapq.heappop(heap),heapq.heappop(heap)
for ai in ais:
	if ai == v:
		print u
	else:
		print v
