B. Tree Journey
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
4 2
1 4
2 4
3 4
1 2
3 3
Output
9
Input
5 5
2 3
1 3
1 4
4 5
1 2
2 3
3 1
4 4
5 5
Output
4