# 入力
N = int(input())

num_list = []
for i in range(N):
    num_list.append(int(input()))

num_set = set(num_list)    
num_max = max(num_set)
for i in range(N):
    if num_list[i] >= num_max:
        target = num_list[:i] + num_list[i+1:]
        if num_max in target:
        	print(num_max)
        else:
          	print(max(set(target)))
    else:
        print(num_max)