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

# S = sorted(A)
# MAXS = max(S[1:3])
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)
#
for i in range(N):

    if i == 0:
        print(max(A[1:]))

    elif i == N-1:
        print(max(A[:i]))

    else:
        low = max(A[0:i])
        high = max(A[i+1:])

        if high > low:
            print(high)
        else:
            print(low)
