n = int(input())
a_max = 0
data = [int(input()) for i in range(n)]
a_max = max(data)
flag = True if a_max == a_max(data.remove(a_max)) else False
for i in range(n):
  if data[i] == a_max and not flag:
    tmp = data.pop(data[i])
    print(max(data))
    data.append(tmp,0)
    
  else:
  	print(a_max)