def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    max_A = max(A)
    max_A_2 = 1
    if len(set(A)) == 1:
        max_A_2 = max_A
    else:
        for a in A:
            if max_A_2 < a and a != max_A:
                max_A_2 = a

    for a in A:
        if a != max_A:
            print(max_A)
        else:
            print(max_A_2)


if __name__ == '__main__':
    main()
