N=int(input())
A=[int(input()) for i in range(N)]
A.insert(0,0)
A.insert(N+1,0)
ans=max(A)
for i in range(1,N+1):
  if A[i]!=ans:
    print(ans)
  else:
    m1=max(A[:i])
    m2=max(A[i+1:])
    m=max(m1,m2)
    print(m)