N = int(input()) #1行目のNを取得する
s = []
s = [input() for i in range(N)] #複数行の数値の入力を取得

buf = s.copy()
max_ind = s.index(max(s))
max_num = max(s)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)