Milk Scheduling

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John has NN cows that need to be milked. Milking one cow takes exactly one unit of time.

The cows are impatient, so a cow refuses to be milked if Farmer John waits too long. Cow ii gives gig_i gallons of milk, but only if she is milked before her deadline at time did_i. Time starts at t=0t = 0, so at most xx cows in total can be milked before time xx. In other words, a cow with deadline did_i has to take one of the first did_i slots.

Find the largest amount of milk Farmer John can get if he milks the cows in the best possible order.

Input

The first line contains the number of cows NN. (1N100001 \le N \le 10000)

Each of the next NN lines contains two integers separated by a space: the gallons gig_i and the deadline did_i of cow ii. (1gi10001 \le g_i \le 1000, 1di100001 \le d_i \le 10000)

Output

Print the maximum number of gallons of milk Farmer John can obtain, on one line.