D. Rearrangement
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3 2
4 1
5 8
4 7
Output
9
Input
2 3
1 1 4
5 1 4
Output
10