Little 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.

Difficulty: interview

Starter code:

Solutions:
n, m = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
pr = [0 for i in range(len(a))]
for i in range(1, len(a)):
    pr[i] = pr[i - 1] + a[i]

ans = 0
for i in range(m):
    l, r = list(map(int, input().split()))
    cur = pr[r] - pr[l - 1]
    if cur >= 0:
        ans += cur

print(ans)



n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(m):
    left, right = list(map(int, input().split()))
    sm = 0
    for i in range(left - 1, right):
        sm += a[i]
    if (sm > 0):
        ans += sm
print(ans)


n, m = map(int, input().split())
a = list(map(int, input().split()))
res = 0
for i in range(m):
    curr = 0
    l, r = map(int, input().split())
    for j in range(l - 1, r):
        curr += a[j]
    if curr > 0:
        res += curr
print(res)

#!/usr/bin/env python3

def main():
    try:
        while True:
            n, m = list(map(int, input().split()))
            a = list(map(int, input().split()))
            result = 0
            for i in range(m):
                left, right = list(map(int, input().split()))
                s = sum(a[left - 1:right])
                if s > 0:
                    result += s
            print(result)

    except EOFError:
        pass

main()


n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
pref=[0]
ans=0
for i in a:
    pref.append(pref[-1]+i)
for i in range(m):
    k,l=[int(i) for i in input().split()]
    plus=pref[l]-pref[k-1]
    if plus>0:
        ans+=plus
print(ans)


n, m = list(map(int, input().split()))
line = list(map(int, input().split()))
answer = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    s = 0
    for j in range(a - 1, b):
        s += line[j]
    if s >= 0:
        answer += s
print(answer)    


from math import *
from sys import *
from queue import *
from decimal import *

n,m=(int(z) for z in input().split())
s=[int(z) for z in input().split()]
R=[]
for i in range(m):
  le,r=(int(z) for z in input().split())
  summ=0
  for j in range(le-1,r):
    summ+=s[j]
  R.append(summ)
ans=0
for i in R:
  if i>=0:
    ans+=i
print(ans)

def solve():
    n,m=list(map(int,input().split()))
    flower=list(map(int,input().split()))
    result=0
    for _ in range(m):
        start,end=list(map(int,input().split()))
        subSum=sum(flower[start-1:end])
        if subSum>0:
            result+=subSum
    print(result)

solve()
    
    


n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(m):
    l, r = list(map(int, input().split()))
    s = 0
    for j in range(l - 1, r):
        s += a[j]
    b.append(s)
b.sort()
i = len(b) - 1
ans = 0
while (i >= 0 and b[i] > 0):
    ans += b[i]
    i -= 1
print(ans)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
total = 0
for i in range(m):
    l, r = list(map(int, input().split()))
    ai = a[l-1:r]
    sumai = sum(ai)
    if (sumai>0):
        total += sumai

print(total)


n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
    s = 0
    l, r = map(int, input().split())
    for j in range(l - 1, r):
        s += a[j]
    if s >= 0:
        ans += s
print(ans)

n,m=list(map(int,input().split()))
ip=list(map(int,input().split()))
ans=0
for i in range(m):
    a,b=list(map(int,input().split()))
    s=0
    a-=1
    b-=1
    for j in range(a,b+1):
        s+=ip[j]
    if s>0:
        ans+=s
print(ans)


n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
ans=0
for z in range(m):
    l,r=[int(i) for i in input().split()]
    sum=0
    for i in range(l-1,r):
        sum+=a[i]
    if sum>0:
        ans+=sum
print(ans)

n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

max_sum = 0

for i in range(m):
    l, r = [int(x) for x in input().split()]
    l -= 1

    sucet = sum(a[l:r])

    if sucet > 0:
        max_sum += sucet

print(max_sum)

n,m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = [0]
for x in a:
    s.append(s[-1] + x)
suc = 0
for i in range(m):
    l,r = list(map(int, input().split()))
    l -= 1
    kolko = s[r] - s[l]
    suc += max(0, kolko)
print(suc)


import math,sys,re,itertools,pprint,collections,copy
rs,ri,rai,raf=input,lambda:int(input()),lambda:list(map(int, input().split())),lambda:list(map(float, input().split()))

n, m = rai()
a = rai()
b = [rai() for i in range(m)]
s = 0
for i, j in b:
    t = sum(a[i-1:j])
    if t > 0:
        s += t

print(s)


n, m = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(m):
	a, b = map(int, input().split())
	ans = max(ans, sum(v[a - 1: b]) + ans)
print(ans)

n, m = list(map(int, input().split()))
l1 = list(map(int, input().split()))
ans = 0
for i in range(m):
    sum1 = 0
    l, r = list(map(int, input().split()))
    l -= 1
    r -= 1
    for j in range(l, r + 1):
        sum1 += l1[j]
    if sum1 > 0:
        ans += sum1
print(ans)


def get_line(func=int,sym=' '):
    return [func(i) for i in input().split(sym)]

n,m=get_line()
a=[0]+get_line()
S=[0]*(n+1)
for i in range(n):
    S[i+1]=S[i]+a[i+1]
ans=0
for i in range(m):
    l,r=get_line()
    mood=S[r]-S[l-1]
    if mood>0:
        ans+=mood
print(ans)


n, m = list(map(int, input().split()))

d = list(map(int, input().split()))

answer = 0
for i in range(m):
    i, j = list(map(int, input().split()))
    i -= 1
    t = sum(d[i:j])
    if t > 0:
        answer += t

print(answer)


n, m = map(int, input().split())
arr = [0] + list(map(int, input().split()))
brr = [list(map(int, input().split())) for i in range(m)]
pref = [0] * (n + 1)
for i in range(1, n + 1):
    pref[i] = pref[i - 1] + arr[i]
cnt = 0
for i in range(m):
    cnt += 0 if pref[brr[i][1]]- pref[brr[i][0] - 1] < 0 else pref[brr[i][1]]- pref[brr[i][0] - 1]
print(cnt)

n, m = list(map(int, input().split()))
arr = [int(x) for x in input().split()]
d = [0] * n
ans = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    
    s = 0
    for j in range(a-1, b):
        s += arr[j]
    if s > 0:
        ans += s
print(ans)



flowers, subarrays = list(map(int, input().split(" ")))
moods = list(map(int, input().split(" ")))
added = 0
for i in range(subarrays):
    f, t = list(map(int, input().split(" ")))
    val = sum(moods[f-1:t])
    if val > 0:
        added += val
print(added)


n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
pSums = (n + 1) * [0]
pSums[0] = 0
for i in range(1, n + 1):
    pSums[i] = pSums[i - 1] + a[i - 1]
    
ans = 0
for i in range(m):
    l, r = list(map(int, input().split()))
    curSum = pSums[r] - pSums[l - 1]
    if curSum > 0:
        ans += curSum

print(ans)


n, m = map(int, input().split())
data = list(map(int, input().split()))
ans = 0
for i in range(m):
    li, ri = map(int, input().split())
    li -= 1
    if sum(data[li:ri]) > 0:
        ans += sum(data[li:ri])
print(ans)