def abc_134c(N):
    max_1 = (0, 0)
    max_2 = (0, 0)
    for i in range(N):
        buf = int(input())
        if max_2[1] < buf:
            if max_1[1] < buf:
                max_2 = max_1
                max_1 = (i, buf)
            else:
                max_2 = (i, buf)

    output = [max_1[1] for _ in range(N)]
    output[max_1[0]] = max_2[1]
    print(output)


if __name__ == "__main__":
    N = int(input())
    abc_134c(N)
