from builtins import enumerate, len

import numpy as np
import copy

N = int(input())
nums = []

for i in range(N):
    nums.append(int(input()))

a = np.array(nums)
maxIndex = [i for i, x in enumerate(a) if x == np.max(a)]

max1 = 0
max2 = 0

if(len(maxIndex)==1):
    nums2 = copy.copy(nums)
    nums2.pop(maxIndex[0])
    b = np.array(nums2)
    maxIndex2 = [i for i, x in enumerate(b) if x == np.max(b)]
    max1 = nums[maxIndex[0]]
    max2 = nums2[maxIndex2[0]]
else:
    max1 = nums[maxIndex[0]]
    max2 = nums[maxIndex[0]]

for num in nums:
    if(num!=max1):
        print(max1)
    else:
        print(max2)