n = gets.to_i
arr = Array.new
while line = $stdin.gets
arr.push(line.to_i)
end
if arr[0]>arr[1] then
  max1 = 0
  max2 = 1
else
  max1 = 1
  max2 = 0
end

(n-2).times{|t|
  if arr[t+2] > arr[max2] and arr[t+2] > arr[max1]then
    max2 = max1
    max1 = t+2
  elsif arr[t+2] > arr[max2] then
    max2 = t+2
  end
}
n.times{|t|
  if t == max1 then
    puts arr[max2]
  else
    puts arr[max1]
  end
}