F. Magic Path
time limit per test
3 с
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
6 13
2 1
3 1
4 1
2 5
4 6
27 16 9 30 9 38
Output
432