n = gets.chomp.to_i
arr = Array.new(n)
max = gets.chomp.to_i 
max2 = max 
arr[0] = max 
(1..n-1).each do |i|
	a =  gets.chomp.to_i
	arr[i] = a 
	max = a if max < a 
	max2 = a if max2 < a && a != max
end

n.times do |i|
	puts arr[i] == max ? max2 : max 
end



