# import bisect
# import copy
# import fractions
# import math
# import numpy as np
from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]
    temp=[0]*N

    for i in range(N):
        if A[i]<max(A):
            temp[i]=max(A)
        elif A.count(max(A))!=1:
            temp[i]=max(A)
        else:
            temp[i]=max(A[:i]+A[i+1:])
    for i in temp:
        print(i)



resolve()