F. Destroying Monsters
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
3
3 3
1 2 4
1 3
2 3
2 5
6 7
2 3 6 7 10 13
1 1
3 8
4 6
12 1000000000
2 4
1 5
10 10
7 4
3 8 2 6 1 8 9
7 7
8 9
1 2
3 5
Output
2
4
-1