def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max1_A = max(A)
    A_cp = sorted(A)
    A_cp.pop(-1)
    max2_A = max(A_cp)
    argmax_A = [i for i, x in enumerate(A) if x == max(A)]

    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()
