import copy
n = int(input())
a = [int(input()) for i in range(n)]
pre_max = max(a)

for i in range(n):
  copy_a = copy.copy(a)
  tmp = copy_a.pop(i)
  if pre_max != tmp:
    print(pre_max)
  else:
    this_max = max(copy_a)
    print(this_max)
    pre_max = this_max
  
  