cho.sh
Notes
Loading...

Selling Goods

Time limit

2s

Memory limit

128 MB

Problem

A seller wants to sell one new product for the greatest possible profit. There are N interested buyers. For each buyer i, Ai is the maximum amount they are willing to pay, and Bi is the delivery cost for selling to that buyer.

If the seller sets the price to P, only buyers with Ai at least P are willing to buy. The seller may skip any willing buyer that would not produce profit. Therefore, selling to buyer i contributes P - Bi, and it is useful only when that value is positive.

Given Ai and Bi for all N buyers, find the sale price P that maximizes total profit.

Input

The first line contains N, the number of interested buyers. N is at most 50.

Each of the next N lines contains two nonnegative integers Ai and Bi, separated by a space: the buyer's maximum price and the delivery cost. Both values are at most 10^6, and the delivery cost may be 0.

Output

Print the price that maximizes total profit. If several prices give the same maximum profit, print the lowest such price.

If no price can produce positive profit, print 0.