#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

max_1 = 0
max_2 = 0
max_index = -1
for i in range(N):
    if A[i] > max_1:
        max_1 = A[i]
        max_index = i
    elif a > max_2:
        max_2 = A[i]

for i in range(N):
    if max_1 == max_2:
        print(max_1)
    else:
        if i == max_index:
            print(max_2)
        else:
            print(max_1)