n=gets.chop.to_i
array=[]
for i in 0..n do
 a=gets.to_i
 array[i]=a
end
max=0
index=0
for i in 0..n-1 do
 if array[i]>max
   max=array[i]
   index=i
   end
 end
 max2=max
for j in 0..n-1 do
 if j==index
 max=0
 for k in 0..n-1 do
  if k!=j
  if array[k]>max
    max=array[k]
    end
   end
  end
  
  end
  puts max
  if j==index
      max=max2
  end
end
