n = int(input())
a = [int(input()) for x in range(n)]

copied_arr = a.copy()
max1 = max(a)
copied_arr.remove(max1)
max2 = max(copied_arr)

for x in a:
    if x == max1:
        print(max2)
    else:
        print(max1)
