N = int(raw_input())
A = [int(raw_input()) for i in xrange(N)]

MAX = 999999999999999999999999999999999999999999999999999999999999999999999999999

dp1 = [-MAX for i in xrange(N)]
for i in range(1, N):
    dp1[i] = max(dp1[i - 1], A[i - 1])

dp2 = [-MAX for i in xrange(N)]
for i in range(N - 2, -1, -1):
    dp2[i] = max(dp2[i + 1], A[i + 1])

for i in xrange(N):
    print max(dp1[i], dp2[i])