import sys
input = sys.stdin.readline
import math
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    MAX = max(A)
    Ms = [-1]*N
    for i in range(N):
        if A[i] == MAX:
            A[i] = 0
            Ms[i] = max(A)
            A[i] = MAX
        else:
            Ms[i] = MAX
    for i in range(N):
        print(Ms[i])

if __name__ == '__main__':
    main()