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

for i in range(n):
  b = a[0:i]
  c = a[i+1:]
  if len(b) > 0:
    b = max(b)
  else:
    b = 0
  if len(c) > 0:
    c = max(c)
  else:
    c = 0

  if b > c:
    print(b)
  else:
    print(c)
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """