n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()
mx  = max(li1)

for i in range(n):
    if li1[i]==mx:
        li2.remove(li1[i])
        print(max(li2))
        li2.append(li1[i])
    else:
        print(mx)