N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  if i==0:
    print(sorted(A[i+1:])[-1])
  if i!=0 and i!=N-1:
    li1=sorted(A[:i])[-1]
    li2=sorted(A[i+1:])[-1]
    print(max(li1,li2))
  if i==N-1:
    print(sorted(A[:i])[-1])