F. Financial Crisis
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
2 6
4
1 2
2 2
3 4
4 4
Output
0
Input
2 6
4
1 2
2 2
1 4
2 4
Output
1
Input
1 6
4
1 2
1 2
1 4
1 4
Output
4
Input
8 30
20
1 1
1 30
1 30
2 30
1 1
2 1
1 3
1 15
2 15
2 3
1 10
2 10
2 10
1 20
1 30
1 27
2 27
2 27
1 15
2 15
Output
17