# ABC134
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(set(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()