Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.
The merchants were the most typical, each of them only sold exactly one item, the price was $P_i$, but they would refuse to make a trade with you if your money were less than $Q_i$, and iSea evaluated every item a value $V_i$.
If he had $M$ units of money, what’s the maximum value iSea could get?
$1 \le N \le 500, 1 \le M \le 5000$
$1 \le Pi \le Qi \le 100, 1 \le Vi \le 1000$