n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
c=a
c=sorted(c)
m=c[n-1]
m2=c[n-2]

if m==m2:
  for i in range(n):
    print(m)
else:
  for i in range(n):
    if a.index(m)==i:
      print(m2)
    else:
      print(m)