n=int(input())
a=[int(input()) for i in range(n)]
max = 0
max_ind = 0
max2 = 0
max2_ind = 0

for i in range(n):
  if max < a[i]:
    max = a[i]
    max_ind = i
    max2 = max
    max2_ind = max_ind
    
for i in range(n):
  if i = max_ind:
    print(max2)
  else:
    print(max)
  
