import numpy as np

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

max_idx = np.argmax(a)
first = a[max_idx]
a[max_idx] = 0
second = max(a)
a[max_idx] = first

for i in range(n):
  if a[i] == first:
    print(second)
  else:
    print(first)