B. Buldozer
time limit per test
11 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
12 6
4 2 3 1 6 5 9 8 13 5 3 10
1 2
1 3
1 4
2 5
2 7
3 6
6 8
6 9
4 10
8 11
8 12
2 3
1 12 4
2 3
1 5 10
2 2
2 6
Output
44
39
24
36