n=int(input())
a=[int(input()) for i in range(n)]
max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
  if max1 < a[i]:
    max1 = a[i]
    max1_ind = i
    max2 = max1
    max2_ind = max1_ind
    
for i in range(n):
  if i = max1_ind:
    print(max2)
  else:
    print(max1)
  