parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	a = Array{Int}(n)
	mo = 0
	mt = 0
	for i in 1:n
		a[i] = readline() |> parseInt
		if a[i] > mo
			mt = mo
			mo = a[i]
		elseif a[i]>mt
			mt = a[i]
		end
	end
	for i in 1:n
		println(a[i]==mo?mo:mt)
	end
end

main()