#arc085d. [arc085_d]NRE

[arc085_d]NRE

Problem Statement

You are given a sequence a=a1,...,aNa = \\{a_1, ..., a_N\\} with all zeros, and a sequence b=b1,...,bNb = \\{b_1, ..., b_N\\} consisting of 00 and 11. The length of both is NN.

You can perform QQ kinds of operations. The ii-th operation is as follows:

  • Replace each of ali,ali+1,...,aria_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 11.

Minimize the hamming distance between aa and bb, that is, the number of ii such that aineqbia_i \\neq b_i, by performing some of the QQ operations.

Constraints

  • 1leqNleq200,0001 \\leq N \\leq 200,000
  • bb consists of 00 and 11.
  • 1leqQleq200,0001 \\leq Q \\leq 200,000
  • 1leqlileqrileqN1 \\leq l_i \\leq r_i \\leq N
  • If ineqji \\neq j, either lineqljl_i \\neq l_j or rineqrjr_i \\neq r_j.

Input

Input is given from Standard Input in the following format:

NN b1b_1 b2b_2 ...... bNb_N QQ l1l_1 r1r_1 l2l_2 r2r_2 :: lQl_Q rQr_Q

Output

Print the minimum possible hamming distance.


Sample Input 1

3
1 0 1
1
1 3

Sample Output 1

1

If you choose to perform the operation, aa will become 1,1,1\\{1, 1, 1\\}, for a hamming distance of 11.


Sample Input 2

3
1 0 1
2
1 1
3 3

Sample Output 2

0

If both operations are performed, aa will become 1,0,1\\{1, 0, 1\\}, for a hamming distance of 00.


Sample Input 3

3
1 0 1
2
1 1
2 3

Sample Output 3

1

Sample Input 4

5
0 1 0 1 0
1
1 5

Sample Output 4

2

It may be optimal to perform no operation.


Sample Input 5

9
0 1 0 1 1 1 0 1 0
3
1 4
5 8
6 7

Sample Output 5

3

Sample Input 6

15
1 1 0 0 0 0 0 0 1 0 1 1 1 0 0
9
4 10
13 14
1 7
4 14
9 11
2 6
7 8
3 12
7 13

Sample Output 6

5

Sample Input 7

10
0 0 0 1 0 0 1 1 1 0
7
1 4
2 5
1 3
6 7
9 9
1 5
7 9

Sample Output 7

1