n = int(input())
no1 = -1
no1_i = -1
no2 = -2
no2_i = -1
S = []
for _ in range(n):
    S.append(int(input()))

for i in range(n):
  	if s[i] > no1:
    	no1_i = i
    	no1 = s[i]
    elif s[i] > no2:
    	no2_i = i
    	no2 = s[i]
      
for i in range(n):
 	if no1_i == i:
    	print(no2)
    else:
    	print(no1)