import numpy as np
if __name__ == "__main__":
    N = input()
    for i in range(int(N)):
        tmpA = input()
        if i == 0:
            A = np.array(int(tmpA))
        else:
            A = np.vstack((A,np.array(int(tmpA))))
    allmaxi = np.argmax(A)
    allmax = np.max(A)
    secondA = np.delete(A,allmaxi,axis=0)
    secondmaxi = np.argmax(secondA)
    secondmax = np.max(secondA)

    for i in range(int(N)):
        if i == allmaxi:
            print(secondmax)
        else:
            print(allmax)
        