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

    print(max(A[1:]))

    for i in range(1, N - 1):
        print(max(max(A[:i]), max(A[i + 1 :])))

    print(max(A[:N]))

    return


if __name__ == "__main__":
    main()
