N = gets.chomp.split(" ").map(&:to_i)
arr = readlines.map{|n| n.chomp.to_i}

first = arr.sort{|x,y| y<=>x}[0]
second  = arr.sort{|x,y| y<=>x}[1] 
# p N,arr,first,second
arr.each do |n|
    if n != first
        puts first
    else
        puts second
    end
end