from collections import deque
N = int(input())
A = deque(int(input()) for i in range(N))
for i in range(N):
    M = max(A)
    p= A.pop()
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.appendleft(p)