# -*- coding: utf-8 -*-

import math

if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    value = sorted(A)
    first = value[N-1]
    second = -1
    for i in range(N-1, -1 , -1):
        if value[i] != first:
            second = value[i]
            break


    # print(A)

    for i in range(N):
        if A[i] != first:
            print(first)
        else:
            print(second)

