n=int(input())
arr=[int(input()) for _ in range(n)]
m1=max(arr)
arr2=sorted(arr,reverse=True)
m2=0
for val in arr2:
  if val!=m1:
    m2=val
    break
else:
  m2=m1
for val in arr:
  if val==m1:
    print(m2)
  else:
    print(m1)