# ABC134

import sys

input = sys.stdin.readline



def main():

    n = int(input())

    A = list(map(int, [input() for _ in range(n)]))

    SA = sorted(A)

    ma, ma2 = SA[-1], SA[-2]

    ans = (ma if i != ma else ma2 for i in A)

    print(*ans, sep="\n")





if __name__ == "__main__":

    main()

# ABC134C - Exception Handling

def main():

    N, *A = list(map(int, open(0)))

    sorted_A = sorted(A)

    m1, m2 = sorted_A[-1], sorted_A[-2]

    ans = [m1 if i != m1 else m2 for i in A]

    print(("\n".join(map(str, ans))))





if __name__ == "__main__":

    main()
# ABC134
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(A)
    ma, ma2 = SA[-1], SA[-2]
    ans = (ma if i != ma else ma2 for i in A)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

# ABC134C - Exception Handling
def main():
    N, *A = list(map(int, open(0)))
    sorted_A = sorted(A)
    m1, m2 = sorted_A[-1], sorted_A[-2]
    ans = [m1 if i != m1 else m2 for i in A]
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

-# ABC134 -import sys - -input = sys.stdin.readline - - +# ABC134C - Exception Handling -    n = int(input()) -    A = list(map(int, [input() for _ in range(n)])) -    SA = sorted(A) -    ma, ma2 = SA[-1], SA[-2] -    ans = (ma if i != ma else ma2 for i in A) -    print(*ans, sep="\n") +    N, *A = list(map(int, open(0))) +    sorted_A = sorted(A) +    m1, m2 = sorted_A[-1], sorted_A[-2] +    ans = [m1 if i != m1 else m2 for i in A] +    print(("\n".join(map(str, ans))))