n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
  
  
b=0
c=0
for i in range(n):
  if a[i]>a[b]:
    b=i
  
for i in range(n):
  if i==b:
    continue
  
  if a[i]>a[c]:
    c=i

for i in range(n):
  if a[b]==a[c]:
    print(a[b])
  else:
    if i!=b:
      print(a[b])
    else:
      print(a[c])

  