n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
for i in range(n):
    if a[i] == a_max:
        print(max(max(a[:i]), max(a[i+1:])))    
    else:
        print(a_max)