N = raw_input()
counter = 0
num_array = []
max_data = 0
second_max = 0
while counter < int(N):
  num_array.append(int(raw_input()))
  if(num_array[counter] > max_data):
    max_data = num_array[counter]
  elif(num_array[counter] > second_max):
    second_max = num_array[counter]
  counter += 1
counter = 0  
while counter < int(N):
  if(num_array[counter] != max_data):
    print max_data
  else:
    print second_max
  counter += 1 
 