#abc249f. [abc249_f]Ignore Operations
[abc249_f]Ignore Operations
Problem Statement
Takahashi has an integer . Initially, .
There are operations. The -th operation is represented by two integers and as follows:
- If , replace with .
- If , replace with .
Takahashi may skip any number between and (inclusive) of the operations. When he performs the remaining operations once each without changing the order, find the maximum possible final value of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 1
2 4
2 -3
1 2
2 1
2 -3
Sample Output 1
3
If he skips the -th operation, changes as $0 \\rightarrow 4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3$, so results in . This is the maximum.
Sample Input 2
1 0
2 -1000000000
Sample Output 2
-1000000000
Sample Input 3
10 3
2 3
2 -1
1 4
2 -1
2 5
2 -9
2 2
1 -6
2 5
2 -3
Sample Output 3
15