Display the min and max price in collection does not work correctly

Hi to all

I need to get the min and max value of the price of all the products in the collection

I used this solution:

{% assign priceValue = collection.products | sort: 'price' %}

{{ priceValue[0].price_min | money_without_currency }}
{{ priceValue[-1].price_max | money_without_currency }}

but it’s does not work correctly. It seems as if the value is displayed only on the page (and I have more than one page of products)

Сan anyone tell me where I made a mistake?

I will be grateful for any help!