AT_abc486_d [ABC486D] Monsters
Description
There are $ N $ monsters. The $ i $ -th monster has level $ L_i $ and strength $ P_i $ .
Initially, Takahashi is at level $ 1 $ . For $ i=1,2,\dots,N $ in this order, he does the following.
- If the level of the $ i $ -th monster is higher than Takahashi's level, he cannot fight that monster, and nothing happens.
- Otherwise, Takahashi chooses whether to fight that monster or not.
- If he does not fight, nothing happens.
- If he fights, Takahashi consumes $ P_i $ stamina to defeat the monster, and his level increases by $ 1 $ .
Determine whether it is possible to defeat the $ N $ -th monster, and if it is, find the minimum total stamina consumed to do so.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ L_1 $ $ P_1 $ $ \vdots $ $ L_N $ $ P_N $
Output Format
If it is impossible to defeat the $ N $ -th monster, print `-1`.
If it is possible to defeat the $ N $ -th monster, print the minimum total stamina consumed up to that point.
Explanation/Hint
### Sample Explanation 1
By acting as follows, he can defeat the $ 5 $ -th monster with a total stamina consumption of $ 11001 $ .
- Fight the $ 1 $ -st monster. He consumes $ 1000 $ stamina and reaches level $ 2 $ .
- Cannot fight the $ 2 $ -nd monster.
- Do not fight the $ 3 $ -rd monster.
- Fight the $ 4 $ -th monster. He consumes $ 1 $ stamina and reaches level $ 3 $ .
- Fight the $ 5 $ -th monster. He consumes $ 10000 $ stamina and reaches level $ 4 $ .
The total stamina consumption cannot be made less than $ 11001 $ , so this is the answer.
### Sample Explanation 2
If it is impossible to defeat the $ N $ -th monster, print `-1`.
### Constraints
- $ 1 \leq N \leq 6000 $
- $ 1 \leq L_i \leq 10^9 $
- $ 1 \leq P_i \leq 10^9 $
- All given numbers are integers.