Problem Statement
We have a grid with 2 rows and L columns. Let (i,j) denote the square at the i-th row from the top (iinlbrace1,2rbrace) and j-th column from the left (1leqjleqL). (i,j) has an integer xi,j written on it.
Find the number of integers j such that x1,j=x2,j.
Here, the description of xi,j is given to you as the run-length compressions of (x1,1,x1,2,ldots,x1,L) and (x2,1,x2,2,ldots,x2,L) into sequences of lengths N1 and N2, respectively: ((v1,1,l1,1),ldots,(v1,N1,l1,N1)) and ((v2,1,l2,1),ldots,(v2,N2,l2,N2)).
Here, the run-length compression of a sequence A is a sequence of pairs (vi,li) of an element vi of A and a positive integer li obtained as follows.
- Split A between each pair of different adjacent elements.
- For each sequence B1,B2,ldots,Bk after the split, let vi be the element of Bi and li be the length of Bi.
Constraints
- 1leqLleq1012
- 1leqN1,N2leq105
- 1leqvi,jleq109(iinlbrace1,2rbrace,1leqjleqNi)
- 1leqli,jleqL(iinlbrace1,2rbrace,1leqjleqNi)
- vi,jneqvi,j+1(iinlbrace1,2rbrace,1leqjltNi)
- li,1+li,2+cdots+li,Ni=L(iinlbrace1,2rbrace)
- All values in the input are integers.
The input is given from Standard Input in the following format:
L N1 N2
v1,1 l1,1
v1,2 l1,2
vdots
v1,N1 l1,N1
v2,1 l2,1
v2,2 l2,2
vdots
v2,N2 l2,N2
Output
Print a single line containing the answer.
Sample Output 1
The grid is shown below.

We have four integers j such that x1,j=x2,j: j=1,2,5,8. Thus, you should print 4.
Sample Output 2
Note that the answer may not fit into a 32-bit integer.
Sample Output 3