A = [int(input()) for i in range(int(input()))]
if len(set(A)) == 1:
    first,second = A[0],A[0]
else:
    first,second = (sorted(set(A),reverse=True))[0],(sorted(set(A),reverse=True))[1]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)