def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print(max(A[1:]))
            elif i == N:
                print(max(A[:N]))
            else:
                print(max(max(A[:i]), max(A[i + 1 :])))

    return


if __name__ == "__main__":
    main()
