def main():
    N = int(input())
    # [4, 3, 3, 1, 3, 2]
    A = [int(input()) for _ in range(N)]
    current_max = max(A[1:N])
    # print('---')
    print(current_max)
    previous_max = current_max
    for i in range(1, N):
        if A[i] != previous_max:
            current_max = max([A[i-1], previous_max])
        else:
            current_max = max(A[0:i] + A[i+1:N])
        print(current_max)
        previous_max = current_max


if __name__ == '__main__':
    main()
