N = int(input())
A = [0]*N

for i in range(N):
  A[i] = int(input())

  M = max(A)
for i in range(N):
  if M == A[i]:
    Atmp = A[0:i]
    Atmp.extend(A[i+1:N])
    ans = max(Atmp)
    print(ans)
  else:
    print(M)
