N = int(input())
al = [int(input()) for _ in range(0, N)]

max_a = max(al)
try:
  snd_a = max(filter(lambda x: x != max_a, al))
except:
  snd_a = max_a
  
for a in al:
  if a == max_a:
    print(snd_a)
  else:
    print(max_a)