Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

B. Alyona and flowers

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputLittle Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a*_{i}. The mood can be positive, zero or negative.

Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.

For example, consider the case when the mother has 5 flowers, and their moods are equal to 1, - 2, 1, 3, - 4. Suppose the mother suggested subarrays (1, - 2), (3, - 4), (1, 3), (1, - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:

- the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,
- the second flower adds ( - 2)·1 = - 2, because he is in one of chosen subarrays,
- the third flower adds 1·2 = 2, because he is in two of chosen subarrays,
- the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,
- the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays.

Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!

Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.

Input

The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.

The second line contains the flowers moods — *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n} ( - 100 ≤ *a*_{i} ≤ 100).

The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l*_{i} and *r*_{i} (1 ≤ *l*_{i} ≤ *r*_{i} ≤ *n*) denoting the subarray *a*[*l*_{i}], *a*[*l*_{i} + 1], ..., *a*[*r*_{i}].

Each subarray can encounter more than once.

Output

Print single integer — the maximum possible value added to the Alyona's happiness.

Examples

Input

5 4

1 -2 1 3 -4

1 2

4 5

3 4

1 4

Output

7

Input

4 3

1 2 3 4

1 3

2 4

1 1

Output

16

Input

2 2

-1 -2

1 1

1 2

Output

0

Note

The first example is the situation described in the statements.

In the second example Alyona should choose all subarrays.

The third example has answer 0 because Alyona can choose none of the subarrays.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/13/2017 16:05:01 (c2).

Desktop version, switch to mobile version.

User lists

Name |
---|