s = int(input())
list =[]
for i in range(s):
  a=int(input())
  list.append(a)
d = max(list)
count=-1
for q in list:
  count +=1
  if q == d:
    list[count]=0
    print(max(list))
  else:
    print(d)