n = gets.chomp.to_i

as = []

n.times{
	as << gets.chomp.to_i
}

sorted_a = as.sort{ |a,b| b <=> a}

max = sorted_a[0]
max_next = sorted_a[1]

as.each{ |x|
	if x == max then
		puts max_next
	else
		puts max
	end
}
