import sys
N = int(sys.stdin.readline().strip())
sequence = []
biggest = 0
for i in range(N):
    x = int(sys.stdin.readline().strip())
    biggest = max(biggest, x)
    sequence.append(x)

for i in range(N):
    if sequence[i] == biggest:
        print(max(sequence[:i] + sequence[min(N-1,i+1):]))
    else:
        print(biggest)
