def resolve():
    n = int(input())
    nums = []

    for i in range(n):
        input_num = int(input())
        nums.append(input_num)

    max_num, second_num = max(nums[0], nums[1]), min(nums[0], nums[1])

    for i in range(2, n):
        if nums[i] > max_num:
            max_num = nums[i]
            second_num = max_num
        elif nums[i] > second_num:
            second_num = nums[i]

    for i in nums:
        if i == max_num:
            print(second_num)
        else:
            print(max_num)
            
resolve()