import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)

for i in range(n):
    if a[i] == a_max:
        tmp = a.pop(i)
        print(max(a))
        a.insert(i, tmp)
    else:
        print(a_max)
