N = int(input()) 
A = []
 
for j in range(N):
    A += [input()]

maxnumber = max(A)
secondmax = sorted(A)[-2]

for i in range(N):
    if(maxnumber != A[i]):
       print(maxnumber)
    else:
       print(secondmax)
