#C
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))