n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
for i in range(n):
    if a[i] == max(a):
        mx_index = i
        break
a.sort()
for i in range(n):
    print(a[n-2] if i == mx_index else a[n-1])