n = int(input())
a = []
for i in range(n):
  ai = int(input())
  a.append(ai)

mx = max(a)
count = a.count(mx)
mx2 = -1
for i in a:
  if(mx2 < i and i != mx):
    mx2 = i

if(mx2 == -1):
  mx2 = mx
  
for i in a:
  if(i!=mx):
    print(mx)
  else:
    if(count>0):
      print(mx)
    else:
      print(mx2)