n = int(input())

a = [0 for i in range(n)]
for i in range(n):
  a[i] = int(input())
  
aMax = max(a)

for i in range(n):
  if a[i] != aMax:
    print(aMax)
  else:
    if i == 0:
      aMax1=max(a[1:n])
      print(aMax1)
    else:
      aMax2=max(a[0:i],a[i+1:n])
      print(aMax2[0])
