def calc(N, A):
    Amax = [A[0], A[1]]
    for a in A:
        if (a > Amax[0]):
            Amax[1] = Amax[0]
            Amax[0] = a
        elif (a > Amax[1]):
            Amax[1] = a
    result = ''
    for a in A:
        if (a == Amax[0]):
            result += str(Amax[1]) + '\n'
        else:
            result += str(Amax[0]) + '\n'
    return result


N = int(input())
A = [int(input()) for _ in range(N)]
print(calc(N, A))