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

# i-1までのmaxはキャッシュする
m1 = 0
for i in range(n):
  p = a[i - 1]
  if i != 0:
    if m1 < p:
      m1 = p
  
  if i != n - 1:
    c = a[i + 1:]
    cm = max(c)
    if m1 < cm:
      print(cm)
    else:
      print(m1)
  else:
    print(m1)
  
  """
  # 遅すぎる
  b = a.copy()
  del b[i]
  print(max(b))
  # 遅すぎる2
  b = a[0:i]
  c = a[i+1:]
  b += c
  print(max(b))
  """