N = int(input())
a = [ int(input()) for i in range(N) ]

max_a = max(a)
ans = [max_a]*N
max_index = []
for i in range(N):
  if a[i] == max_a:
    max_index.append(i)
try:
  sec_max_a = max([i for i in a if i !=max_a])
except:
  for i in range(N):
    print(ans[i])
else:
  for i in max_index:
    ans[i]=sec_max_a
  for i in range(N):
    print(ans[i])