# -*- coding: utf-8 -*-

n = int(input())

a = []

for i in range(n):
    a.append(int(input()))

a_max = max(a)

for i in range(0,n):
    if a[i] == a_max:
        a1 = a[:i]
        a2 = a[i+1:]

        if len(a1) == 0:
                print(max(a2))
        elif len(a2) == 0:
            print(max(a1)) 
        else:
            print(max(max(a1), max(a2)))
    else:
        print(a_max)

    
