n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]

for i in range(n):
  if i in m_index:
    b = a[i]
    del a[i]
    print(max(a))
    a.insert(i, b)
  else:
    print(m_num)