You went to a gaming parlor to play some games. There are total N games. In beginning you are allowed to play only one game. Each game outputs 2 numbers, P and Q. P is the score that you got on that game and Q is the number of more games that you can play. Q adds up to the number of games that you could previously play (suppose you could play 4 games before playing the current game. You played current game and got Q as 3. Now you can play 4-1+3=6 more games.). A game can only be played once. You stop when your allowed game counter becomes 0 or you have played all N games.
Your score in a game adds up to your total score. Find the maximum possible total score.
INPUT
First line contains the integer N, denoting number of games.
Each of the next N lines contains 2 integers, P and Q. P is the score that you got on that game and Q is the number of more games that you can play.
OUTPUT
Output single integer, maximum total score possible.
CONSTRAINTS
1<=N<=1000
0<=P,Q<=105