n=int(input())
a=[]
b=[]
for i in range(n):
  k=int(input())
  a.append(k)
  b.append(k)
for j in range(n):
  if b[j]==max(a):
    a.remove(b[j])
    print(max(a))
    a.append(b[j])
  else:
    print(max(a))