E. Painting a Wall
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
6 5
01101
1 2
2 3
6 6
3 4
4 5
Output
3
Input
1 2
01
1 1
1 1
Output
1